From 284bb81bbfa4283e070591c357ad67cfce6944cd Mon Sep 17 00:00:00 2001 From: Awesome Code Date: Sat, 9 Feb 2019 03:05:40 +0000 Subject: [PATCH] Auto corrected by following Lint Ruby RSpecEmptyLine --- spec/controllers/admin_controller_spec.rb | 2 ++ .../api/v1/plantings_controller_spec.rb | 6 ++++++ .../controllers/charts/crops_controller_spec.rb | 6 ++++++ .../charts/gardens_controller_spec.rb | 2 ++ spec/controllers/comments_controller_spec.rb | 1 + spec/controllers/gardens_controller_spec.rb | 8 ++++++++ spec/controllers/harvests_controller_spec.rb | 13 +++++++++++++ spec/controllers/likes_controller_spec.rb | 2 ++ spec/controllers/member_controller_spec.rb | 1 + spec/controllers/photos_controller_spec.rb | 5 +++++ spec/controllers/plantings_controller_spec.rb | 17 +++++++++++++++++ spec/controllers/seeds_controller_spec.rb | 4 ++++ spec/factories/notifications.rb | 1 + spec/features/crops/crop_wranglers_spec.rb | 1 + spec/features/crops/show_spec.rb | 2 ++ spec/features/gardens/actions_spec.rb | 3 +++ spec/features/home/home_spec.rb | 1 + spec/features/plantings/planting_a_crop_spec.rb | 1 + spec/features/seeds/adding_seeds_spec.rb | 1 + spec/features/seeds/misc_seeds_spec.rb | 11 +++++++++++ spec/helpers/buttons_helper_spec.rb | 1 + spec/models/crop_spec.rb | 1 + spec/models/member_spec.rb | 1 + spec/models/planting_spec.rb | 1 + spec/models/post_spec.rb | 1 + spec/models/seed_spec.rb | 2 ++ spec/requests/api/v1/crop_request_spec.rb | 2 ++ spec/requests/api/v1/harvest_request_spec.rb | 2 ++ spec/requests/api/v1/member_request_spec.rb | 2 ++ spec/requests/api/v1/photos_request_spec.rb | 2 ++ spec/requests/api/v1/seeds_request_spec.rb | 2 ++ spec/views/posts/new.html.haml_spec.rb | 1 + spec/views/posts/show.html.haml_spec.rb | 1 + spec/views/seeds/show.html.haml_spec.rb | 1 + 34 files changed, 108 insertions(+) diff --git a/spec/controllers/admin_controller_spec.rb b/spec/controllers/admin_controller_spec.rb index 5aa87e7cb..ad6cba550 100644 --- a/spec/controllers/admin_controller_spec.rb +++ b/spec/controllers/admin_controller_spec.rb @@ -5,6 +5,7 @@ describe AdminController do describe "GET admin/newsletter" do before { get :newsletter } + describe 'fetches the admin newsletter page' do it { expect(response).to be_success } it { expect(response).to render_template("admin/newsletter") } @@ -12,6 +13,7 @@ describe AdminController do describe 'assigns @members' do let!(:m) { FactoryBot.create(:newsletter_recipient_member) } + it { expect(assigns(:members)).to eq [m] } end end diff --git a/spec/controllers/api/v1/plantings_controller_spec.rb b/spec/controllers/api/v1/plantings_controller_spec.rb index 2c9368945..57b450d94 100644 --- a/spec/controllers/api/v1/plantings_controller_spec.rb +++ b/spec/controllers/api/v1/plantings_controller_spec.rb @@ -4,6 +4,7 @@ require 'rails_helper' RSpec.describe Api::V1::PlantingsController, type: :controller do subject { JSON.parse response.body } + let(:headers) do { 'Accept' => 'application/vnd.api+json', @@ -37,11 +38,14 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do 'thumbnail' => nil } end + before { get :index, format: :json } + it { expect(matching_planting).to include('id' => my_planting.id.to_s) } it { expect(matching_planting['attributes']).to eq expected_attributes } it { expect(response.status).to eq 200 } end + context 'with photo' do let!(:my_planting) { FactoryBot.create(:planting, owner: member, planted_at: '2000-01-01') } @@ -65,10 +69,12 @@ RSpec.describe Api::V1::PlantingsController, type: :controller do } end let(:photo) { FactoryBot.create(:photo, owner: my_planting.owner) } + before do my_planting.photos << photo get :index, format: :json end + it { expect(matching_planting).to include('id' => my_planting.id.to_s) } it { expect(matching_planting['attributes']).to eq expected_attributes } it { expect(response.status).to eq 200 } diff --git a/spec/controllers/charts/crops_controller_spec.rb b/spec/controllers/charts/crops_controller_spec.rb index 962b57891..120179c78 100644 --- a/spec/controllers/charts/crops_controller_spec.rb +++ b/spec/controllers/charts/crops_controller_spec.rb @@ -3,16 +3,22 @@ require 'rails_helper' describe Charts::CropsController do describe 'GET charts' do let(:crop) { FactoryBot.create :crop } + describe 'sunniness' do before { get :sunniness, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end + describe 'planted_from' do before { get :planted_from, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end + describe 'harvested_for' do before { get :harvested_for, params: { crop_slug: crop.to_param } } + it { expect(response).to be_success } end end diff --git a/spec/controllers/charts/gardens_controller_spec.rb b/spec/controllers/charts/gardens_controller_spec.rb index c0d331876..6c3843446 100644 --- a/spec/controllers/charts/gardens_controller_spec.rb +++ b/spec/controllers/charts/gardens_controller_spec.rb @@ -9,6 +9,7 @@ describe Charts::GardensController do context "when not signed in" do describe 'GET timeline' do before { get :timeline, params: { garden_id: garden.to_param } } + it { expect(response).to be_success } end end @@ -20,6 +21,7 @@ describe Charts::GardensController do describe 'GET timeline' do before { get :timeline, params: { garden_id: garden.to_param } } + it { expect(response).to be_success } end end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 4d9e9fc6b..6d9a707af 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -54,6 +54,7 @@ describe CommentsController do describe "GET edit" do let(:post) { FactoryBot.create(:post) } + before { get :edit, params: { id: comment.to_param } } describe "my comment" do diff --git a/spec/controllers/gardens_controller_spec.rb b/spec/controllers/gardens_controller_spec.rb index 720ba5a7b..4e40f5ffa 100644 --- a/spec/controllers/gardens_controller_spec.rb +++ b/spec/controllers/gardens_controller_spec.rb @@ -9,11 +9,13 @@ RSpec.describe GardensController, type: :controller do context "when not signed in" do describe 'GET new' do before { get :new, params: { id: garden.to_param } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'PUT create' do before { put :create, params: { garden: valid_params } } + it { expect(response).to redirect_to(new_member_session_path) } end @@ -29,16 +31,19 @@ RSpec.describe GardensController, type: :controller do describe 'GET edit' do before { get :edit, params: { id: garden.to_param } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'POST update' do before { post :update, params: { id: garden.to_param, garden: valid_params } } + it { expect(response).to redirect_to(new_member_session_path) } end describe 'DELETE' do before { delete :destroy, params: { id: garden.to_param, params: { garden: valid_params } } } + it { expect(response).to redirect_to(new_member_session_path) } end end @@ -63,16 +68,19 @@ RSpec.describe GardensController, type: :controller do describe 'GET edit' do before { get :edit, params: { id: not_my_garden.to_param } } + it { expect(response).to redirect_to(root_path) } end describe 'POST update' do before { post :update, params: { id: not_my_garden.to_param, garden: valid_params } } + it { expect(response).to redirect_to(root_path) } end describe 'DELETE' do before { delete :destroy, params: { id: not_my_garden.to_param, params: { garden: valid_params } } } + it { expect(response).to redirect_to(root_path) } end end diff --git a/spec/controllers/harvests_controller_spec.rb b/spec/controllers/harvests_controller_spec.rb index b7259293e..6853ff477 100644 --- a/spec/controllers/harvests_controller_spec.rb +++ b/spec/controllers/harvests_controller_spec.rb @@ -22,17 +22,20 @@ describe HarvestsController do describe "assigns all harvests as @harvests" do before { get :index, params: {} } + it { expect(assigns(:harvests)).to eq [harvest1, harvest2] } end describe "picks up owner from params and shows owner's harvests only" do before { get :index, params: { member_slug: member1.slug } } + it { expect(assigns(:owner)).to eq member1 } it { expect(assigns(:harvests)).to eq [harvest1] } end describe "picks up crop from params and shows the harvests for the crop only" do before { get :index, params: { crop_slug: maize.name } } + it { expect(assigns(:crop)).to eq maize } it { expect(assigns(:harvests)).to eq [harvest2] } end @@ -49,6 +52,7 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { get :show, params: { id: harvest.to_param } } + it { expect(assigns(:harvest)).to eq(harvest) } end end @@ -70,6 +74,7 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { get :edit, params: { id: harvest.to_param } } + it { expect(assigns(:harvest)).to eq(harvest) } end end @@ -84,18 +89,22 @@ describe HarvestsController do describe "assigns a newly created harvest as @harvest" do before { post :create, params: { harvest: valid_attributes } } + it { expect(assigns(:harvest)).to be_a(Harvest) } it { expect(assigns(:harvest)).to be_persisted } end describe "redirects to the created harvest" do before { post :create, params: { harvest: valid_attributes } } + it { expect(response).to redirect_to(Harvest.last) } end describe "links to planting" do let(:planting) { FactoryBot.create(:planting, owner_id: member.id, garden: member.gardens.first) } + before { post :create, params: { harvest: valid_attributes.merge(planting_id: planting.id) } } + it { expect(Harvest.last.planting.id).to eq(planting.id) } end end @@ -111,6 +120,7 @@ describe HarvestsController do describe "re-renders the 'new' template" do # Trigger the behavior that occurs when invalid params are submitted before { post :create, params: { harvest: { "crop_id" => "invalid value" } } } + it { expect(response).to render_template("new") } end end @@ -133,6 +143,7 @@ describe HarvestsController do describe "PUT update" do describe "with valid params" do let(:harvest) { Harvest.create! valid_attributes } + it "updates the requested harvest" do new_crop = FactoryBot.create :crop expect do @@ -143,11 +154,13 @@ describe HarvestsController do describe "assigns the requested harvest as @harvest" do before { put :update, params: { id: harvest.to_param, harvest: valid_attributes } } + it { expect(assigns(:harvest)).to eq(harvest) } end describe "redirects to the harvest" do before { put :update, params: { id: harvest.to_param, harvest: valid_attributes } } + it { expect(response).to redirect_to(harvest) } end end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index c27d05de9..09f6ee251 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -11,6 +11,7 @@ describe LikesController do describe "POST create" do it { expect(response.content_type).to eq "application/json" } before { post :create, params: { post_id: blogpost.id, format: :json } } + it { expect(Like.last.likeable_id).to eq(blogpost.id) } it { expect(Like.last.likeable_type).to eq('Post') } it { JSON.parse(response.body)["description"] == "1 like" } @@ -26,6 +27,7 @@ describe LikesController do describe "DELETE destroy" do before { delete :destroy, params: { id: like.id, format: :json } } + it { expect(response.content_type).to eq "application/json" } describe "un-liking something i liked before" do diff --git a/spec/controllers/member_controller_spec.rb b/spec/controllers/member_controller_spec.rb index 34ef19c34..025b66701 100644 --- a/spec/controllers/member_controller_spec.rb +++ b/spec/controllers/member_controller_spec.rb @@ -58,6 +58,7 @@ describe MembersController do describe "GET member's RSS feed" do describe "returns an RSS feed" do before { get :show, params: { slug: @member.to_param }, format: "rss" } + it { response.should be_success } it { response.should render_template("members/show") } it { response.content_type.should eq("application/rss+xml") } diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index e49d3b194..36ccb436b 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -39,6 +39,7 @@ describe PhotosController do describe "planting photos" do before(:each) { get :new, params: { type: "planting", id: planting.id } } + it { assigns(:flickr_auth).should be_an_instance_of(Authentication) } it { assigns(:item).should eq planting } it { expect(flash[:alert]).not_to be_present } @@ -47,12 +48,14 @@ describe PhotosController do describe "harvest photos" do before { get :new, params: { type: "harvest", id: harvest.id } } + it { assigns(:item).should eq harvest } it { expect(flash[:alert]).not_to be_present } end describe "garden photos" do before { get :new, params: { type: "garden", id: garden.id } } + it { expect(assigns(:item)).to eq garden } it { expect(flash[:alert]).not_to be_present } end @@ -130,6 +133,7 @@ describe PhotosController do describe "for the second time" do let(:planting) { FactoryBot.create :planting, owner: member } let(:valid_params) { { photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting' } } + it "does not add a photo twice" do expect { post :create, params: valid_params }.to change(Photo, :count).by(1) expect { post :create, params: valid_params }.not_to change(Photo, :count) @@ -151,6 +155,7 @@ describe PhotosController do before do post :create, params: { photo: { flickr_photo_id: photo.flickr_photo_id }, type: "harvest", id: harvest.id } end + it { expect(flash[:alert]).not_to be_present } it { expect(Photo.last.harvests.first).to eq harvest } end diff --git a/spec/controllers/plantings_controller_spec.rb b/spec/controllers/plantings_controller_spec.rb index c4a60d1a4..d0a5c11a6 100644 --- a/spec/controllers/plantings_controller_spec.rb +++ b/spec/controllers/plantings_controller_spec.rb @@ -26,12 +26,14 @@ describe PlantingsController do describe "picks up owner from params and shows owner's plantings only" do before { get :index, params: { member_slug: member1.slug } } + it { expect(assigns(:owner)).to eq member1 } it { expect(assigns(:plantings)).to eq [planting1] } end describe "picks up crop from params and shows the plantings for the crop only" do before { get :index, params: { crop_slug: maize.slug } } + it { expect(assigns(:crop)).to eq maize } it { expect(assigns(:plantings)).to eq [planting2] } end @@ -40,44 +42,56 @@ describe PlantingsController do describe "GET new" do describe "picks up crop from params" do let(:crop) { FactoryBot.create(:crop) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).to eq(crop) } end describe "doesn't die if no crop specified" do before { get :new, params: {} } + it { expect(assigns(:crop)).to be_a_new(Crop) } end describe "picks up member's garden from params" do let(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { garden_id: garden.id } } + it { expect(assigns(:garden)).to eq(garden) } end describe "Doesn't display another member's garden on planting form" do let(:another_member) { FactoryBot.create(:member) } # over-riding member from login_member() let(:garden) { FactoryBot.create(:garden, owner: another_member) } + before { get :new, params: { garden_id: garden.id } } + it { expect(assigns(:garden)).not_to eq(garden) } end describe "Doesn't display un-approved crops on planting form" do let(:crop) { FactoryBot.create(:crop, approval_status: 'pending') } let!(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).not_to eq(crop) } end describe "Doesn't display rejected crops on planting form" do let(:crop) { FactoryBot.create(:crop, approval_status: 'rejected', reason_for_rejection: 'nope') } let!(:garden) { FactoryBot.create(:garden, owner: member) } + before { get :new, params: { crop_id: crop.id } } + it { expect(assigns(:crop)).not_to eq(crop) } end describe "doesn't die if no garden specified" do before { get :new, params: {} } + it { expect(assigns(:garden)).to be_a_new(Garden) } end @@ -89,7 +103,9 @@ describe PlantingsController do context 'with parent seed' do let(:seed) { FactoryBot.create :seed, owner: member } + before { get :new, params: { seed_id: seed.to_param } } + it { expect(assigns(:seed)).to eq(seed) } end end @@ -97,6 +113,7 @@ describe PlantingsController do describe 'POST :create' do describe "sets the owner automatically" do before { post :create, params: { planting: valid_attributes } } + it { expect(assigns(:planting).owner).to eq subject.current_member } end end diff --git a/spec/controllers/seeds_controller_spec.rb b/spec/controllers/seeds_controller_spec.rb index 3c90841d1..eefaa1c36 100644 --- a/spec/controllers/seeds_controller_spec.rb +++ b/spec/controllers/seeds_controller_spec.rb @@ -5,8 +5,10 @@ describe SeedsController do describe "GET index" do let(:owner) { FactoryBot.create(:member) } + describe "picks up owner from params" do before { get :index, params: { member_slug: owner.slug } } + it { expect(assigns(:owner)).to eq(owner) } end end @@ -22,7 +24,9 @@ describe SeedsController do context 'with parent planting' do let(:planting) { FactoryBot.create :planting, owner: owner } + before { get :new, params: { planting_id: planting.to_param } } + it { expect(assigns(:planting)).to eq(planting) } end end diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb index b0b3dce97..4d2cee82f 100644 --- a/spec/factories/notifications.rb +++ b/spec/factories/notifications.rb @@ -5,6 +5,7 @@ FactoryBot.define do sender { FactoryBot.create :member } recipient { FactoryBot.create :member } subject { "MyString" } + body { "MyText" } read { false } post diff --git a/spec/features/crops/crop_wranglers_spec.rb b/spec/features/crops/crop_wranglers_spec.rb index 86dc8a1c0..4dc8633ac 100644 --- a/spec/features/crops/crop_wranglers_spec.rb +++ b/spec/features/crops/crop_wranglers_spec.rb @@ -34,6 +34,7 @@ feature "crop wranglers", js: true do describe "visiting a crop can see wrangler links" do before { visit crop_path(crops.first) } + it { expect(page).to have_content 'You are a CROP WRANGLER' } it { expect(page).to have_link 'Edit' } it { expect(page).to have_link 'Delete' } diff --git a/spec/features/crops/show_spec.rb b/spec/features/crops/show_spec.rb index 76d6b9530..245e60b00 100644 --- a/spec/features/crops/show_spec.rb +++ b/spec/features/crops/show_spec.rb @@ -13,6 +13,7 @@ feature "browse crops" do context "when the most recently created harvest is not the most recently harvested" do before { FactoryBot.create_list :harvest, 20, crop: tomato, harvested_at: 1.year.ago, created_at: 1.minute.ago } + let!(:most_recent_harvest) do FactoryBot.create :harvest, crop: tomato, harvested_at: 60.minutes.ago, created_at: 10.minute.ago end @@ -25,6 +26,7 @@ feature "browse crops" do context "when the most recently created planting is not the most recently planted" do before { FactoryBot.create_list :planting, 20, crop: tomato, planted_at: 1.year.ago, created_at: 1.minute.ago } + let!(:most_recent_planting) do FactoryBot.create :planting, crop: tomato, planted_at: 60.minutes.ago, created_at: 10.minute.ago end diff --git a/spec/features/gardens/actions_spec.rb b/spec/features/gardens/actions_spec.rb index 8c5068415..98337063d 100644 --- a/spec/features/gardens/actions_spec.rb +++ b/spec/features/gardens/actions_spec.rb @@ -55,13 +55,16 @@ feature "Gardens" do describe '#show' do describe 'my garden' do before { visit garden_path(garden) } + it { is_expected.to have_link 'Edit' } it { is_expected.to have_link 'Delete' } it { is_expected.to have_content "Plant something here" } it { is_expected.to have_content "Add photo" } end + describe "someone else's garden" do before { visit garden_path(other_member_garden) } + it { is_expected.not_to have_link 'Edit' } it { is_expected.not_to have_link 'Delete' } it { is_expected.not_to have_content "Plant something here" } diff --git a/spec/features/home/home_spec.rb b/spec/features/home/home_spec.rb index d02bb619f..812f84710 100644 --- a/spec/features/home/home_spec.rb +++ b/spec/features/home/home_spec.rb @@ -87,6 +87,7 @@ feature "home page" do describe 'should say welcome' do before { visit root_path } + it { expect(page).to have_content "Welcome to #{ENV['GROWSTUFF_SITE_NAME']}, #{member.login_name}" } end end diff --git a/spec/features/plantings/planting_a_crop_spec.rb b/spec/features/plantings/planting_a_crop_spec.rb index 5e750a615..9711453a4 100644 --- a/spec/features/plantings/planting_a_crop_spec.rb +++ b/spec/features/plantings/planting_a_crop_spec.rb @@ -233,6 +233,7 @@ feature "Planting a crop", :js, :elasticsearch do click_button "Save" end end + it { expect(page).to have_content "planting was successfully created" } it { expect(page).to have_content "Finished: Yes (no date specified)" } it { expect(page).to have_content "100%" } diff --git a/spec/features/seeds/adding_seeds_spec.rb b/spec/features/seeds/adding_seeds_spec.rb index 021a24336..f87d8f59d 100644 --- a/spec/features/seeds/adding_seeds_spec.rb +++ b/spec/features/seeds/adding_seeds_spec.rb @@ -47,6 +47,7 @@ feature "Seeds", :js, :elasticsearch do click_button "Save" end end + it { expect(page).to have_content "Successfully added maize seed to your stash" } it { expect(page).to have_content "Quantity: 42" } it { expect(page).to have_content "Days until maturity: 999–1999" } diff --git a/spec/features/seeds/misc_seeds_spec.rb b/spec/features/seeds/misc_seeds_spec.rb index fafcc3d12..e7c1e0291 100644 --- a/spec/features/seeds/misc_seeds_spec.rb +++ b/spec/features/seeds/misc_seeds_spec.rb @@ -10,10 +10,12 @@ feature "seeds", js: true do describe "button on index to edit seed" do let!(:seed) { create :seed, owner: member } + before do visit seeds_path click_link "edit_seed_glyphicon" end + it { expect(current_path).to eq edit_seed_path(seed) } it { expect(page).to have_content 'Editing seeds' } end @@ -23,6 +25,7 @@ feature "seeds", js: true do visit root_path click_link "Save seeds" end + it { expect(current_path).to eq new_seed_path } it { expect(page).to have_content 'Save seeds' } end @@ -32,6 +35,7 @@ feature "seeds", js: true do visit member_seeds_path(member) click_link "View #{member}'s profile >>" end + it { expect(current_path).to eq member_path(member) } end @@ -49,32 +53,39 @@ feature "seeds", js: true do describe "delete seeds" do let(:seed) { FactoryBot.create :seed, owner: member } + before do visit seed_path(seed) click_link 'Delete' end + it { expect(current_path).to eq seeds_path } end describe '#show' do before { visit seed_path(seed) } + describe "view seeds with max and min days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_min: 5, days_until_maturity_max: 7 } + it { expect(page).to have_content "Days until maturity: 5–7" } end describe "view seeds with only max days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_max: 7 } + it { expect(page).to have_content "Days until maturity: 7" } end describe "view seeds with only min days until maturity" do let(:seed) { FactoryBot.create :seed, days_until_maturity_min: 5 } + it { expect(page).to have_content "Days until maturity: 5" } end describe "view seeds with neither max nor min days until maturity" do let(:seed) { FactoryBot.create :seed } + it { expect(page).to have_content "Days until maturity: unknown" } end end diff --git a/spec/helpers/buttons_helper_spec.rb b/spec/helpers/buttons_helper_spec.rb index d3def8e00..d23bde14f 100644 --- a/spec/helpers/buttons_helper_spec.rb +++ b/spec/helpers/buttons_helper_spec.rb @@ -12,6 +12,7 @@ require 'rails_helper' # end RSpec.describe ButtonsHelper, type: :helper do before { allow(self).to receive(:can?) { true } } + let(:garden) { FactoryBot.create :garden } let(:planting) { FactoryBot.create :planting } let(:harvest) { FactoryBot.create :harvest } diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 1b8de81ed..e580add1b 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -288,6 +288,7 @@ describe Crop do let(:crop2_planting) { crop2.plantings.first } let(:member) { FactoryBot.create :member, login_name: 'pikachu' } + describe 'lists interesting crops' do before do # they need 3+ plantings each to be interesting diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index e1b176378..c6342e60a 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -6,6 +6,7 @@ describe 'member' do describe 'should be fetchable from the database' do subject { Member.find(member.id) } + it { is_expected.to be_an_instance_of Member } it { expect(subject.encrypted_password).not_to be_nil } end diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 29241db3f..b84388395 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -332,6 +332,7 @@ describe Planting do context 'photos' do let(:planting) { FactoryBot.create(:planting) } let(:photo) { FactoryBot.create(:photo, owner_id: planting.owner_id) } + before { planting.photos << photo } it 'has a photo' do diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index eeda089d2..f02a7c6a7 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' describe Post do let(:member) { FactoryBot.create(:member, login_name: 'whinacooper') } + it_behaves_like "it is likeable" it "should have a slug" do diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index d71fbeda7..d2b201972 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -154,6 +154,7 @@ describe Seed do let(:seed) { FactoryBot.create :seed } before { seed.photos << FactoryBot.create(:photo, owner: seed.owner) } + it 'is found in has_photos scope' do Seed.has_photos.should include(seed) end @@ -162,6 +163,7 @@ describe Seed do context 'ancestry' do let(:parent_planting) { FactoryBot.create :planting } let(:seed) { FactoryBot.create :seed, parent_planting: parent_planting, owner: parent_planting.owner } + it "seed has a parent planting" do expect(seed.parent_planting).to eq(parent_planting) end diff --git a/spec/requests/api/v1/crop_request_spec.rb b/spec/requests/api/v1/crop_request_spec.rb index 31212ab2c..64e7bcf1a 100644 --- a/spec/requests/api/v1/crop_request_spec.rb +++ b/spec/requests/api/v1/crop_request_spec.rb @@ -58,11 +58,13 @@ RSpec.describe 'Plantings', type: :request do describe '#index' do before { get '/api/v1/crops', params: {}, headers: headers } + it { expect(subject['data']).to include(crop_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/crops/#{crop.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) } diff --git a/spec/requests/api/v1/harvest_request_spec.rb b/spec/requests/api/v1/harvest_request_spec.rb index c4fddd350..5b1c9b0a8 100644 --- a/spec/requests/api/v1/harvest_request_spec.rb +++ b/spec/requests/api/v1/harvest_request_spec.rb @@ -59,11 +59,13 @@ RSpec.describe 'Harvests', type: :request do describe '#index' do before { get '/api/v1/harvests', params: {}, headers: headers } + it { expect(subject['data']).to include(harvest_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/harvests/#{harvest.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("planting" => planting_as_json_api) } it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) } diff --git a/spec/requests/api/v1/member_request_spec.rb b/spec/requests/api/v1/member_request_spec.rb index f44b2a4ae..9178f91cc 100644 --- a/spec/requests/api/v1/member_request_spec.rb +++ b/spec/requests/api/v1/member_request_spec.rb @@ -59,11 +59,13 @@ RSpec.describe 'Members', type: :request do describe '#index' do before { get '/api/v1/members', params: {}, headers: headers } + it { expect(subject['data']).to include(member_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/members/#{member.id}", params: {}, headers: headers } + it { expect(subject['data']['relationships']).to include("gardens" => gardens_as_json_api) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("seeds" => seeds_as_json_api) } diff --git a/spec/requests/api/v1/photos_request_spec.rb b/spec/requests/api/v1/photos_request_spec.rb index 15fb8cd19..833e5499c 100644 --- a/spec/requests/api/v1/photos_request_spec.rb +++ b/spec/requests/api/v1/photos_request_spec.rb @@ -57,11 +57,13 @@ RSpec.describe 'Photos', type: :request do describe '#index' do before { get '/api/v1/photos', params: {}, headers: headers } + it { expect(subject['data']).to include(photo_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/photos/#{photo.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("plantings" => plantings_as_json_api) } it { expect(subject['data']['relationships']).to include("harvests" => harvests_as_json_api) } diff --git a/spec/requests/api/v1/seeds_request_spec.rb b/spec/requests/api/v1/seeds_request_spec.rb index 909d08864..000d55e14 100644 --- a/spec/requests/api/v1/seeds_request_spec.rb +++ b/spec/requests/api/v1/seeds_request_spec.rb @@ -46,11 +46,13 @@ RSpec.describe 'Photos', type: :request do describe '#index' do before { get '/api/v1/seeds', params: {}, headers: headers } + it { expect(subject['data']).to include(seed_encoded_as_json_api) } end describe '#show' do before { get "/api/v1/seeds/#{seed.id}", params: {}, headers: headers } + it { expect(subject['data']['attributes']).to eq(attributes) } it { expect(subject['data']['relationships']).to include("owner" => owner_as_json_api) } it { expect(subject['data']['relationships']).to include("crop" => crop_as_json_api) } diff --git a/spec/views/posts/new.html.haml_spec.rb b/spec/views/posts/new.html.haml_spec.rb index 6c6a2ae68..77da034a9 100644 --- a/spec/views/posts/new.html.haml_spec.rb +++ b/spec/views/posts/new.html.haml_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' describe "posts/new" do let(:author) { FactoryBot.create(:member) } + before(:each) do assign(:post, FactoryBot.create(:post, author: author)) # assign(:forum, Forum.new) diff --git a/spec/views/posts/show.html.haml_spec.rb b/spec/views/posts/show.html.haml_spec.rb index 8a9733039..39868b314 100644 --- a/spec/views/posts/show.html.haml_spec.rb +++ b/spec/views/posts/show.html.haml_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' describe "posts/show" do subject { rendered } + let(:author) { FactoryBot.create(:member, login_name: 'mary') } before(:each) do diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index 2ad38bdcf..114df46fb 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -2,6 +2,7 @@ require 'rails_helper' describe "seeds/show" do let(:seed) { FactoryBot.create(:seed) } + before(:each) do controller.stub(:current_user) { nil } assign(:seed, seed)