mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 19:23:59 -04:00
Various corrections
This commit is contained in:
@@ -170,14 +170,6 @@ RSpec/Capybara/VisibilityMatcher:
|
||||
Exclude:
|
||||
- 'spec/features/shared_examples/crop_suggest.rb'
|
||||
|
||||
# Offense count: 2
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
# Configuration parameters: NegatedMatcher.
|
||||
RSpec/ChangeByZero:
|
||||
Exclude:
|
||||
- 'spec/models/comment_spec.rb'
|
||||
- 'spec/models/post_spec.rb'
|
||||
|
||||
# Offense count: 292
|
||||
# Configuration parameters: Prefixes, AllowedPatterns.
|
||||
# Prefixes: when, with, without
|
||||
@@ -211,47 +203,6 @@ RSpec/EmptyExampleGroup:
|
||||
- 'spec/views/photos/edit.html.haml_spec.rb'
|
||||
- 'spec/views/posts/_single.html.haml_spec.rb'
|
||||
|
||||
# Offense count: 78
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
# Configuration parameters: AllowConsecutiveOneLiners.
|
||||
RSpec/EmptyLineAfterExample:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 13
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
RSpec/EmptyLineAfterExampleGroup:
|
||||
Exclude:
|
||||
- 'spec/controllers/crops_controller_spec.rb'
|
||||
- 'spec/controllers/posts_controller_spec.rb'
|
||||
- 'spec/features/cms_spec.rb'
|
||||
- 'spec/features/crops/creating_a_crop_spec.rb'
|
||||
- 'spec/features/likeable_spec.rb'
|
||||
- 'spec/features/seeds/adding_seeds_spec.rb'
|
||||
- 'spec/features/timeline/index_spec.rb'
|
||||
- 'spec/models/planting_spec.rb'
|
||||
- 'spec/services/crop_search_service_spec.rb'
|
||||
|
||||
# Offense count: 51
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
RSpec/EmptyLineAfterFinalLet:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 88
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
# Configuration parameters: AllowConsecutiveOneLiners.
|
||||
RSpec/EmptyLineAfterHook:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 6
|
||||
# This cop supports safe autocorrection (--autocorrect).
|
||||
RSpec/EmptyLineAfterSubject:
|
||||
Exclude:
|
||||
- 'spec/controllers/crops_controller_spec.rb'
|
||||
- 'spec/features/members/deletion_spec.rb'
|
||||
- 'spec/helpers/event_helper_spec.rb'
|
||||
- 'spec/services/crop_search_service_spec.rb'
|
||||
- 'spec/services/timeline_service_spec.rb'
|
||||
|
||||
# Offense count: 136
|
||||
# Configuration parameters: CountAsOne.
|
||||
RSpec/ExampleLength:
|
||||
|
||||
@@ -11,11 +11,13 @@ describe Admin::RolesController do
|
||||
|
||||
describe "GET index" do
|
||||
before { get :index }
|
||||
|
||||
it { expect(assigns(:roles)).to be_nil }
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
before { get :new }
|
||||
|
||||
it { expect(assigns(:role)).to be_nil }
|
||||
end
|
||||
|
||||
@@ -27,11 +29,13 @@ describe Admin::RolesController do
|
||||
|
||||
describe "GET edit" do
|
||||
before { get :edit, params: { id: role.to_param } }
|
||||
|
||||
it { expect(assigns(:role)).to be_nil }
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
before { patch :update, params: { id: role.id, role: { name: 'updated role' } } }
|
||||
|
||||
it { expect(Role.first.name).to eq 'MyString' }
|
||||
end
|
||||
end
|
||||
@@ -41,11 +45,13 @@ describe Admin::RolesController do
|
||||
|
||||
describe "GET index" do
|
||||
before { get :index }
|
||||
|
||||
it { expect(assigns(:roles)).to eq([Role.find_by(name: 'admin'), role]) }
|
||||
end
|
||||
|
||||
describe "GET new" do
|
||||
before { get :new }
|
||||
|
||||
it { expect(assigns(:role)).to be_a(Role) }
|
||||
end
|
||||
|
||||
@@ -59,11 +65,13 @@ describe Admin::RolesController do
|
||||
|
||||
describe "GET edit" do
|
||||
before { get :edit, params: { id: role.to_param } }
|
||||
|
||||
it { expect(assigns(:role)).to eq(role) }
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
before { patch :update, params: { id: role.id, role: { name: 'updated role' } } }
|
||||
|
||||
it { expect(Role.first.name).to eq 'updated role' }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +44,9 @@ describe CropsController do
|
||||
describe 'fetches the crop search page' do
|
||||
let!(:tomato) { FactoryBot.create :tomato }
|
||||
let!(:maize) { FactoryBot.create :maize }
|
||||
|
||||
before { Crop.reindex }
|
||||
|
||||
describe 'search form page' do
|
||||
before { get :search }
|
||||
|
||||
@@ -54,6 +56,7 @@ describe CropsController do
|
||||
|
||||
describe 'perform a search' do
|
||||
before { get :search, params: { term: 'tom' } }
|
||||
|
||||
it { expect(assigns(:term)).to eq 'tom' }
|
||||
it { expect(assigns(:crops).map(&:name)).to eq ['tomato'] }
|
||||
end
|
||||
@@ -81,13 +84,17 @@ describe CropsController do
|
||||
sci_name: { "1": "fancy sci name", "2": "" }
|
||||
}
|
||||
end
|
||||
|
||||
subject { put :create, params: crop_params }
|
||||
|
||||
context 'not logged in' do
|
||||
it { expect { subject }.not_to change(Crop, :count) }
|
||||
end
|
||||
|
||||
context 'logged in as member' do
|
||||
it { expect { subject }.not_to change(Crop, :count) }
|
||||
end
|
||||
|
||||
context 'wrangler' do
|
||||
include_context 'login as wrangler'
|
||||
it { expect { subject }.to change(Crop, :count).by(1) }
|
||||
|
||||
@@ -36,6 +36,7 @@ describe PhotosController, :search do
|
||||
it "has indexed the photos of this crop" do
|
||||
expect(Photo.search).to include crop_photo
|
||||
end
|
||||
|
||||
it "assigns crop" do
|
||||
expect(assigns(:crop)).to eq crop
|
||||
end
|
||||
@@ -112,6 +113,7 @@ describe PhotosController, :search do
|
||||
type: "planting", id: planting.id
|
||||
}
|
||||
end
|
||||
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(Photo.last.plantings.first).to eq planting }
|
||||
end
|
||||
@@ -145,6 +147,7 @@ describe PhotosController, :search do
|
||||
photo: { source_id: photo.source_id, source: 'flickr' }, type: "harvest", id: harvest.id
|
||||
}
|
||||
end
|
||||
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(Photo.last.harvests.size).to eq 1 }
|
||||
end
|
||||
@@ -175,7 +178,9 @@ describe PhotosController, :search do
|
||||
describe "creates the planting/photo link" do
|
||||
let(:planting) { FactoryBot.create(:planting, garden:, owner: member) }
|
||||
let(:photo) { FactoryBot.create(:photo, owner: member) }
|
||||
|
||||
before { post :create, params: { photo: { source_id: photo.source_id, source: 'flickr' }, type: "planting", id: planting.id } }
|
||||
|
||||
it { expect(flash[:alert]).not_to be_present }
|
||||
it { expect(Photo.last.plantings.first).to eq planting }
|
||||
end
|
||||
|
||||
@@ -19,6 +19,7 @@ describe PlantingsController, :search do
|
||||
let!(:maize) { FactoryBot.create(:maize) }
|
||||
let!(:planting1) { FactoryBot.create :planting, crop: tomato, owner: member1, created_at: 1.day.ago }
|
||||
let!(:planting2) { FactoryBot.create :planting, crop: maize, owner: member2, created_at: 5.days.ago }
|
||||
|
||||
before do
|
||||
Planting.reindex
|
||||
end
|
||||
@@ -129,8 +130,10 @@ describe PlantingsController, :search do
|
||||
describe 'GET :edit' do
|
||||
let(:my_planting) { FactoryBot.create :planting, owner: member }
|
||||
let(:not_my_planting) { FactoryBot.create :planting }
|
||||
|
||||
context 'my planting' do
|
||||
before { get :edit, params: { slug: my_planting } }
|
||||
|
||||
it { expect(assigns(:planting)).to eq my_planting }
|
||||
end
|
||||
|
||||
|
||||
@@ -15,12 +15,16 @@ describe PostsController do
|
||||
FactoryBot.create_list :post, 100
|
||||
FactoryBot.create_list :post, 5, author: member
|
||||
end
|
||||
|
||||
describe "everyone's posts" do
|
||||
before { get :index }
|
||||
|
||||
it { expect(assigns(:posts).size).to eq 12 }
|
||||
end
|
||||
|
||||
describe "one member's posts" do
|
||||
before { get :index, params: { member_slug: member.slug } }
|
||||
|
||||
it { expect(assigns(:posts).size).to eq 5 }
|
||||
it { expect(assigns(:posts).first.author).to eq member }
|
||||
end
|
||||
|
||||
@@ -13,6 +13,7 @@ describe "forums", js: true do
|
||||
click_link "Forums"
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path forums_path, ignore_query: true }
|
||||
it { expect(page).to have_link "New forum" }
|
||||
end
|
||||
@@ -26,6 +27,7 @@ describe "forums", js: true do
|
||||
fill_in 'Description', with: "this is a new forum"
|
||||
click_button 'Save'
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path forum_path(Forum.last), ignore_query: true }
|
||||
it { expect(page).to have_content 'Forum was successfully created' }
|
||||
end
|
||||
@@ -38,6 +40,7 @@ describe "forums", js: true do
|
||||
click_button 'Save'
|
||||
forum.reload
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path forum_path(forum), ignore_query: true }
|
||||
it { expect(page).to have_content 'Forum was successfully updated' }
|
||||
it { expect(page).to have_content 'Something else' }
|
||||
@@ -50,6 +53,7 @@ describe "forums", js: true do
|
||||
click_link 'Delete'
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path forums_path, ignore_query: true }
|
||||
it { expect(page).to have_content 'Forum was successfully deleted' }
|
||||
end
|
||||
|
||||
@@ -17,6 +17,7 @@ describe "cms admin" do
|
||||
expect(page).to have_content "Please sign in as an admin user"
|
||||
end
|
||||
end
|
||||
|
||||
context 'admin' do
|
||||
include_context 'signed in admin'
|
||||
it "admin members can view CMS admin area" do
|
||||
|
||||
@@ -17,6 +17,7 @@ describe "Conversations", :js do
|
||||
click_link recipient.login_name
|
||||
click_link 'Inbox'
|
||||
end
|
||||
|
||||
it { expect(page).to have_content 'something i want to say' }
|
||||
it { page.percy_snapshot(page, name: 'conversations#index') }
|
||||
|
||||
@@ -28,13 +29,17 @@ describe "Conversations", :js do
|
||||
|
||||
describe 'view trash' do
|
||||
before { click_link 'trash' }
|
||||
|
||||
it { expect(page).to have_content 'something i want to say' }
|
||||
|
||||
describe 'restore conversation' do
|
||||
before { click_link class: 'restore' }
|
||||
|
||||
it { expect(page).not_to have_content 'something i want to say' }
|
||||
|
||||
describe 'conversation was restored' do
|
||||
before { click_link 'inbox' }
|
||||
|
||||
it { expect(page).to have_content 'something i want to say' }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,6 +28,7 @@ describe "Conversations", :js do
|
||||
fill_in :body, with: 'i like this too'
|
||||
click_button 'Send'
|
||||
end
|
||||
|
||||
it { expect(page).to have_content "i like this too" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@ describe "Crop", js: true do
|
||||
click_button "Save"
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(page).to have_content 'crop was successfully created.' }
|
||||
it { expect(page).to have_content "This crop is currently pending approval." }
|
||||
it { expect(page).to have_content "Jasminum sambac 2" }
|
||||
@@ -43,6 +44,7 @@ describe "Crop", js: true do
|
||||
before do
|
||||
click_button "Save"
|
||||
end
|
||||
|
||||
it { expect(page).to have_content 'crop was successfully created.' }
|
||||
it { expect(page).to have_content "Jasminum sambac 2" }
|
||||
it { expect(page).to have_content "Matsurika" }
|
||||
@@ -51,16 +53,20 @@ describe "Crop", js: true do
|
||||
|
||||
context 'anon' do
|
||||
before { visit new_crop_path }
|
||||
|
||||
it { expect(page).to have_content 'You need to sign in' }
|
||||
end
|
||||
|
||||
context 'member' do
|
||||
include_context 'signed in member'
|
||||
include_examples 'request crop'
|
||||
end
|
||||
|
||||
context 'crop wrangler' do
|
||||
include_context 'signed in crop wrangler'
|
||||
include_examples 'create crop'
|
||||
end
|
||||
|
||||
context 'admin' do
|
||||
include_context 'signed in admin'
|
||||
include_examples 'create crop'
|
||||
|
||||
@@ -6,6 +6,7 @@ describe "crop detail page", js: true do
|
||||
before do
|
||||
FactoryBot.create :plant_part, name: 'leaf'
|
||||
end
|
||||
|
||||
subject do
|
||||
# Update the medians after all the
|
||||
# data has been loaded
|
||||
@@ -34,12 +35,15 @@ describe "crop detail page", js: true do
|
||||
click_link 'Add to my garden'
|
||||
expect(page).to have_link "add new garden"
|
||||
end
|
||||
|
||||
it "has a link to harvest the crop" do
|
||||
click_link 'Record harvest'
|
||||
expect(page).to have_link "leaf"
|
||||
end
|
||||
|
||||
describe "Saving seeds" do
|
||||
before { click_link 'Save seeds' }
|
||||
|
||||
it { expect(page).to have_text "Will you offer these seeds for trade?" }
|
||||
it { expect(page).to have_button "locally" }
|
||||
it { expect(page).to have_button "nationally" }
|
||||
@@ -94,10 +98,12 @@ describe "crop detail page", js: true do
|
||||
context 'signed in' do
|
||||
include_context 'signed in member'
|
||||
before { seed.update! owner: member }
|
||||
|
||||
it "User signed in" do
|
||||
visit crop_path(seed.crop)
|
||||
expect(page).to have_link "You have 20 seeds of this crop."
|
||||
end
|
||||
|
||||
it "click link to your owned seeds" do
|
||||
visit crop_path(seed.crop)
|
||||
click_link "You have 20 seeds of this crop."
|
||||
|
||||
@@ -65,6 +65,7 @@ describe "crop detail page", :js, :search do
|
||||
context "when signed in as photos owner" do
|
||||
include_context 'signed in member'
|
||||
let(:member) { owner_member }
|
||||
|
||||
include_examples "shows photos"
|
||||
end
|
||||
|
||||
|
||||
@@ -5,18 +5,21 @@ require 'rails_helper'
|
||||
describe "crop wrangling button" do
|
||||
context 'not signed in' do
|
||||
before { visit crops_path }
|
||||
|
||||
it { expect(page).not_to have_link "Wrangle Crops", href: wrangle_crops_path }
|
||||
end
|
||||
|
||||
context "signed in, but not a crop wrangler" do
|
||||
include_context 'signed in member'
|
||||
before { visit crops_path }
|
||||
|
||||
it { expect(page).not_to have_link "Wrangle Crops", href: wrangle_crops_path }
|
||||
end
|
||||
|
||||
context "signed in crop wrangler" do
|
||||
include_context 'signed in crop wrangler'
|
||||
before { visit crops_path }
|
||||
|
||||
it { expect(page).to have_link "Wrangle Crops", href: wrangle_crops_path }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,7 +14,9 @@ describe "browse crops" do
|
||||
let!(:cherry) { FactoryBot.create :crop, name: 'cherry tomato', parent: tomato }
|
||||
let!(:heirloom) { FactoryBot.create :crop, name: 'heirloom tomato', parent: tomato }
|
||||
let!(:striped) { FactoryBot.create :crop, name: 'striped tomato', parent: heirloom }
|
||||
|
||||
before { visit crop_path(tomato) }
|
||||
|
||||
it { expect(page).to have_link heirloom.name, href: crop_path(heirloom) }
|
||||
it { expect(page).to have_link cherry.name, href: crop_path(cherry) }
|
||||
it { expect(page).to have_link striped.name, href: crop_path(striped) }
|
||||
|
||||
@@ -29,6 +29,7 @@ describe "Gardens" do
|
||||
|
||||
context 'with actions menu expanded' do
|
||||
before { click_link 'Actions' }
|
||||
|
||||
it "has actions on garden" do
|
||||
expect(subject).to have_link 'Plant something here'
|
||||
expect(subject).to have_link 'Mark as inactive'
|
||||
@@ -61,6 +62,7 @@ describe "Gardens" do
|
||||
|
||||
context 'with actions menu expanded' do
|
||||
before { click_link 'Actions' }
|
||||
|
||||
it { is_expected.to have_link 'Edit' }
|
||||
it { is_expected.to have_link 'Delete' }
|
||||
it { is_expected.to have_content "Plant something here" }
|
||||
@@ -70,6 +72,7 @@ describe "Gardens" do
|
||||
|
||||
describe "someone else's garden" do
|
||||
before { visit garden_path(other_member_garden) }
|
||||
|
||||
it { is_expected.not_to have_link 'Actions' }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,6 +19,7 @@ describe "Gardens#index", :js do
|
||||
expect(page).to have_text garden.name
|
||||
end
|
||||
end
|
||||
|
||||
it "links to each garden" do
|
||||
member.gardens.each do |garden|
|
||||
expect(page).to have_link(garden.name, href: garden_path(garden))
|
||||
@@ -35,12 +36,15 @@ describe "Gardens#index", :js do
|
||||
it "show active garden" do
|
||||
expect(page).to have_text active_garden.name
|
||||
end
|
||||
|
||||
it "does not show inactive garden" do
|
||||
expect(page).not_to have_text inactive_garden.name
|
||||
end
|
||||
|
||||
it "links to active garden" do
|
||||
expect(page).to have_link(active_garden.name, href: garden_path(active_garden))
|
||||
end
|
||||
|
||||
it "does not link to inactive gardens" do
|
||||
expect(page).not_to have_link(inactive_garden.name, href: garden_path(inactive_garden))
|
||||
end
|
||||
@@ -64,6 +68,7 @@ describe "Gardens#index", :js do
|
||||
it "shows planting in garden" do
|
||||
expect(page).to have_link(planting.crop.name, href: planting_path(planting))
|
||||
end
|
||||
|
||||
it "does not show finished planting" do
|
||||
expect(page).not_to have_text(finished_planting.crop.name)
|
||||
end
|
||||
|
||||
@@ -42,7 +42,9 @@ describe "Harvesting a crop", :js, :search do
|
||||
|
||||
describe 'member harvests' do
|
||||
before { visit member_harvests_path(member) }
|
||||
|
||||
it { expect(page).to have_text "#{member.login_name}'s harvests" }
|
||||
|
||||
it "Clicking link to owner's profile" do
|
||||
within '.login-name' do
|
||||
click_link member.login_name
|
||||
@@ -64,6 +66,7 @@ describe "Harvesting a crop", :js, :search do
|
||||
|
||||
describe "Harvesting from planting page" do
|
||||
let!(:planting) { create :planting, crop: maize, owner: member, garden: member.gardens.first }
|
||||
|
||||
before do
|
||||
visit planting_path(planting)
|
||||
click_link "Record harvest"
|
||||
|
||||
@@ -37,9 +37,11 @@ describe "home page", :search do
|
||||
it "show tradeable seed" do
|
||||
expect(subject).to have_link href: seed_path(tradable_seed)
|
||||
end
|
||||
|
||||
it "does not show finished seeds" do
|
||||
expect(subject).not_to have_link href: seed_path(finished_seed)
|
||||
end
|
||||
|
||||
it "does not show untradable seeds" do
|
||||
expect(subject).not_to have_link href: seed_path(untradable_seed)
|
||||
end
|
||||
@@ -64,12 +66,14 @@ describe "home page", :search do
|
||||
shared_examples "show crops" do
|
||||
describe 'shows crops section' do
|
||||
before { crop.reindex }
|
||||
|
||||
it { is_expected.to have_text 'Some of our crops' }
|
||||
it { is_expected.to have_link href: crop_path(crop) }
|
||||
end
|
||||
|
||||
describe 'shows recently added crops' do
|
||||
it { is_expected.to have_text 'Recently Added' }
|
||||
|
||||
it 'link to newest crops' do
|
||||
expect(subject).to have_link crop.name, href: crop_path(crop)
|
||||
end
|
||||
|
||||
@@ -53,24 +53,32 @@ describe 'Likeable', :js, search: true do
|
||||
end
|
||||
describe 'photos#index' do
|
||||
let(:path) { photos_path }
|
||||
|
||||
include_examples 'photo can be liked'
|
||||
end
|
||||
|
||||
describe 'photos#show' do
|
||||
let(:path) { photo_path(photo) }
|
||||
|
||||
include_examples 'photo can be liked'
|
||||
end
|
||||
|
||||
describe 'crops#show' do
|
||||
let(:crop) { FactoryBot.create :crop }
|
||||
let(:planting) { FactoryBot.create :planting, owner: member, crop: }
|
||||
let(:path) { crop_path(crop) }
|
||||
|
||||
before { planting.photos << photo }
|
||||
|
||||
include_examples 'photo can be liked'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'posts' do
|
||||
let(:like_count_class) { "#post-#{post.id} .like-count" }
|
||||
|
||||
before { visit post_path(post) }
|
||||
|
||||
it 'can be liked' do
|
||||
expect(page).to have_css(like_count_class, text: "0")
|
||||
expect(page).to have_link 'Like'
|
||||
|
||||
@@ -6,6 +6,7 @@ describe "Changing locales", js: true do
|
||||
after { I18n.locale = :en }
|
||||
|
||||
let(:member) { FactoryBot.create :member }
|
||||
|
||||
it "Locale can be set with a query param" do
|
||||
# Login then log out, to ensure we're now logged out
|
||||
login_as member
|
||||
|
||||
@@ -9,11 +9,14 @@ describe "members list" do
|
||||
context 'logged in as admin' do
|
||||
include_context 'signed in admin'
|
||||
before { visit member_path(spammer) }
|
||||
|
||||
it { expect(page).to have_link "Ban member" }
|
||||
|
||||
describe 'bans the user' do
|
||||
before do
|
||||
accept_confirm { click_link 'Ban member' }
|
||||
end
|
||||
|
||||
it { expect(page).to have_link admin.login_name }
|
||||
it { expect(page).not_to have_link spammer.login_name }
|
||||
end
|
||||
|
||||
@@ -89,6 +89,7 @@ describe "member deletion" do
|
||||
|
||||
describe 'member exists but is marked deleted' do
|
||||
subject { Member.all.find(member.id) }
|
||||
|
||||
it { expect(subject).to eq member }
|
||||
it { expect(subject.discarded?).to be true }
|
||||
it { expect(Member.kept).not_to include(member) }
|
||||
@@ -158,6 +159,7 @@ describe "member deletion" do
|
||||
let(:otherwrangler) { FactoryBot.create(:crop_wrangling_member) }
|
||||
let(:crop) { FactoryBot.create(:crop, creator: member) }
|
||||
before { FactoryBot.create(:cropbot) }
|
||||
|
||||
let!(:ex_wrangler) { FactoryBot.create(:crop_wrangling_member, login_name: "ex_wrangler") }
|
||||
|
||||
it "leaves crops behind" do
|
||||
|
||||
@@ -44,6 +44,7 @@ describe "member profile", js: true do
|
||||
visit member_path(public_member)
|
||||
expect(page).to have_content public_member.email
|
||||
end
|
||||
|
||||
it "private email address" do
|
||||
visit member_path(member)
|
||||
expect(page).not_to have_content member.email
|
||||
@@ -65,7 +66,9 @@ describe "member profile", js: true do
|
||||
let!(:harvest) { FactoryBot.create :harvest, owner: member }
|
||||
let!(:seed) { FactoryBot.create :seed, owner: member }
|
||||
let!(:post) { FactoryBot.create :post, author: member }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link(href: planting_path(planting)) }
|
||||
it { expect(page).to have_link(href: harvest_path(harvest)) }
|
||||
it { expect(page).to have_link(href: seed_path(seed)) }
|
||||
@@ -88,6 +91,7 @@ describe "member profile", js: true do
|
||||
describe 'user role labels' do
|
||||
describe "admin user's page" do
|
||||
before { visit member_path(admin_member) }
|
||||
|
||||
it { expect(page).to have_text "Admin" }
|
||||
end
|
||||
|
||||
@@ -110,7 +114,9 @@ describe "member profile", js: true do
|
||||
let!(:old_planting) { FactoryBot.create :planting, owner: member, planted_at: 3.years.ago }
|
||||
let!(:finished_planting) { FactoryBot.create :finished_planting, owner: member }
|
||||
let!(:no_planted_at_planting) { FactoryBot.create :planting, owner: member, planted_at: nil }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: planting_path(new_planting) }
|
||||
it { expect(page).to have_link href: planting_path(old_planting) }
|
||||
it { expect(page).to have_link href: planting_path(finished_planting) }
|
||||
@@ -119,26 +125,34 @@ describe "member profile", js: true do
|
||||
|
||||
context 'member has seeds' do
|
||||
let!(:seed) { FactoryBot.create :seed, owner: member }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: seed_path(seed) }
|
||||
end
|
||||
|
||||
context 'member has harvests' do
|
||||
let!(:harvest) { FactoryBot.create :harvest, owner: member }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: harvest_path(harvest) }
|
||||
end
|
||||
|
||||
context 'member has posts' do
|
||||
let!(:post) { FactoryBot.create :post, author: member }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: post_path(post) }
|
||||
end
|
||||
|
||||
context 'member has comments' do
|
||||
let(:post) { FactoryBot.create :post }
|
||||
let!(:comment) { FactoryBot.create :comment, post:, author: member }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: post_path(post) }
|
||||
it { expect(page).to have_link href: comment_path(comment) }
|
||||
end
|
||||
@@ -146,7 +160,9 @@ describe "member profile", js: true do
|
||||
context 'photos' do
|
||||
let(:planting) { FactoryBot.create :planting, owner: member }
|
||||
let!(:photo) { FactoryBot.create :photo, owner: member, plantings: [planting] }
|
||||
|
||||
before { visit member_path(member) }
|
||||
|
||||
it { expect(page).to have_link href: photo_path(photo) }
|
||||
it { expect(page).to have_link href: planting_path(planting) }
|
||||
end
|
||||
@@ -230,6 +246,7 @@ describe "member profile", js: true do
|
||||
it "has a private message button" do
|
||||
expect(page).to have_link "Send message", href: new_message_path(recipient_id: other_member.id)
|
||||
end
|
||||
|
||||
it { expect(page).not_to have_link "Edit profile", href: edit_member_registration_path }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,7 @@ describe 'Test with visual testing', js: true, type: :feature do
|
||||
# Use the same random seed every time so our random data is the same
|
||||
# on every run, so doesn't trigger percy to see changes
|
||||
before { Faker::Config.random = Random.new(42) }
|
||||
|
||||
let!(:member) { FactoryBot.create :member, login_name: 'percy', preferred_avatar_uri: gravatar }
|
||||
let!(:crop_wrangler) { FactoryBot.create :crop_wrangling_member, login_name: 'croppy', preferred_avatar_uri: gravatar2 }
|
||||
let!(:admin_user) { FactoryBot.create :admin_member, login_name: 'janitor', preferred_avatar_uri: gravatar3 }
|
||||
@@ -66,6 +67,7 @@ rest of the garden.
|
||||
"
|
||||
end
|
||||
let(:post) { FactoryBot.create :post, author: member, subject: "Watering", body: post_body }
|
||||
|
||||
before do
|
||||
# Freeze time, so we don't have variations in timestamps on the page
|
||||
Timecop.freeze(Time.zone.local(2019, 1, 1))
|
||||
@@ -96,6 +98,7 @@ rest of the garden.
|
||||
FactoryBot.create :seed, owner: member, tradable_to: 'nationally'
|
||||
FactoryBot.create :seed, owner: someone_else, tradable_to: 'nationally'
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
shared_examples 'visit pages' do
|
||||
@@ -124,6 +127,7 @@ rest of the garden.
|
||||
expect(page).to have_text 'tomato'
|
||||
page.percy_snapshot(page, name: "#{prefix}/crops#show")
|
||||
end
|
||||
|
||||
it 'loads crops#index' do
|
||||
visit crops_path
|
||||
page.percy_snapshot(page, name: "#{prefix}/crops#index")
|
||||
@@ -189,6 +193,7 @@ rest of the garden.
|
||||
visit post_path(post)
|
||||
page.percy_snapshot(page, name: "#{prefix}/posts#show")
|
||||
end
|
||||
|
||||
it 'loads posts#index' do
|
||||
Member.all.limit(5).each do |member|
|
||||
FactoryBot.create_list :post, 12, author: member
|
||||
@@ -212,6 +217,7 @@ rest of the garden.
|
||||
|
||||
context "when signed out" do
|
||||
let(:prefix) { 'signed-out' }
|
||||
|
||||
include_examples 'visit pages'
|
||||
|
||||
it 'loads sign in page' do
|
||||
@@ -230,6 +236,7 @@ rest of the garden.
|
||||
visit new_member_password_path
|
||||
page.percy_snapshot(page, name: "forgot-password")
|
||||
end
|
||||
|
||||
it 'loads new confirmation' do
|
||||
visit new_member_confirmation_path
|
||||
page.percy_snapshot(page, name: "new-confimation")
|
||||
@@ -238,6 +245,7 @@ rest of the garden.
|
||||
|
||||
context 'when signed in' do
|
||||
let(:prefix) { 'signed-in' }
|
||||
|
||||
include_context 'signed in member'
|
||||
include_examples 'visit pages'
|
||||
|
||||
@@ -357,29 +365,36 @@ rest of the garden.
|
||||
context 'admin' do
|
||||
include_context 'signed in admin'
|
||||
before { visit admin_path }
|
||||
|
||||
it 'admin page' do
|
||||
page.percy_snapshot(page, name: 'Admin')
|
||||
end
|
||||
|
||||
it 'Roles' do
|
||||
click_link 'Roles'
|
||||
page.percy_snapshot(page, name: 'Admin Roles')
|
||||
end
|
||||
|
||||
it 'CMS' do
|
||||
click_link 'CMS'
|
||||
page.percy_snapshot(page, name: 'CMS')
|
||||
end
|
||||
|
||||
it 'Garden Types' do
|
||||
click_link 'Garden Types'
|
||||
page.percy_snapshot(page, name: 'Admin Garden type')
|
||||
end
|
||||
|
||||
it 'Alternate names' do
|
||||
click_link 'Alternate names'
|
||||
page.percy_snapshot(page, name: 'Admin Alternate names')
|
||||
end
|
||||
|
||||
it 'Scientific names' do
|
||||
click_link 'Scientific names'
|
||||
page.percy_snapshot(page, name: 'Admin Scientific names')
|
||||
end
|
||||
|
||||
it 'Members' do
|
||||
click_link 'Members'
|
||||
page.percy_snapshot(page, name: 'Admin Members')
|
||||
|
||||
@@ -19,6 +19,7 @@ describe "show photo page" do
|
||||
expect(page).to have_link "#{planting.crop.name} planting in #{planting.garden.name} by #{planting.owner}",
|
||||
href: planting_path(planting)
|
||||
}
|
||||
|
||||
it { expect(page).to have_link planting.crop.name }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,7 @@ describe "User searches" do
|
||||
visit places_path
|
||||
search_with "Philippines"
|
||||
end
|
||||
|
||||
it { expect(page).to have_content "community near Philippines" }
|
||||
it { expect(page).to have_button "search_button" }
|
||||
it { expect(page).to have_content "Nearby members" }
|
||||
@@ -30,6 +31,7 @@ describe "User searches" do
|
||||
describe "Nearby plantings, seed, and members" do
|
||||
include_context 'signed in member'
|
||||
let(:member) { located_member }
|
||||
|
||||
before do
|
||||
visit places_path
|
||||
search_with "Philippines"
|
||||
|
||||
@@ -58,6 +58,7 @@ describe "Planting a crop", :js, :search do
|
||||
click_link member.login_name
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path member_path(member), ignore_query: true }
|
||||
end
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ describe "Display a planting", :js do
|
||||
|
||||
describe 'no harvest to predict from' do
|
||||
before { visit planting_path(planting) }
|
||||
|
||||
it { expect(planting.harvest_months).to eq({}) }
|
||||
it { expect(page).to have_content 'We need more data on this crop in your latitude.' }
|
||||
end
|
||||
@@ -20,7 +21,9 @@ describe "Display a planting", :js do
|
||||
FactoryBot.create :harvest, planting: planting, crop: crop, harvested_at: '18 June 2019'
|
||||
FactoryBot.create_list :harvest, 4, planting:, crop:, harvested_at: '18 August 2019'
|
||||
end
|
||||
|
||||
before { visit planting_path(planting) }
|
||||
|
||||
it { expect(page.find_by_id('month-1')[:class]).not_to include("badge-harvesting") }
|
||||
it { expect(page.find_by_id('month-2')[:class]).not_to include("badge-harvesting") }
|
||||
it { expect(page.find_by_id('month-5')[:class]).to include("badge-harvesting") }
|
||||
@@ -51,7 +54,9 @@ describe "Display a planting", :js do
|
||||
FactoryBot.create_list :harvest, 4, planting: faraway_planting, crop:,
|
||||
harvested_at: '18 December 2006'
|
||||
end
|
||||
|
||||
before { visit planting_path(planting) }
|
||||
|
||||
it { expect(page.find_by_id('month-1')[:class]).not_to include("badge-harvesting") }
|
||||
it { expect(page.find_by_id('month-2')[:class]).not_to include("badge-harvesting") }
|
||||
it { expect(page.find_by_id('month-5')[:class]).to include("badge-harvesting") }
|
||||
|
||||
@@ -9,21 +9,25 @@ describe "Display a planting", :js do
|
||||
|
||||
context 'Perennial planted long ago' do
|
||||
let(:planting) { FactoryBot.create :perennial_planting }
|
||||
|
||||
it { expect(page).to have_text 'Perennial' }
|
||||
end
|
||||
|
||||
context 'Perennial finished' do
|
||||
let(:planting) { FactoryBot.create :perennial_planting, planted_at: 6.years.ago, finished: true, finished_at: 1.year.ago }
|
||||
|
||||
it { expect(page).to have_text 'Perennial' }
|
||||
end
|
||||
|
||||
context 'Annual no predictions' do
|
||||
let(:planting) { FactoryBot.create :annual_planting }
|
||||
|
||||
it { expect(page).not_to have_text 'Finish expected' }
|
||||
end
|
||||
|
||||
context 'Annual with predicted finish' do
|
||||
let(:planting) { FactoryBot.create :predicatable_planting, planted_at: 2.weeks.ago }
|
||||
|
||||
it { expect(page).to have_text '28%' }
|
||||
it { expect(page).to have_text '14/50 days' }
|
||||
it { expect(page).to have_text "Planted #{I18n.l(2.weeks.ago.to_date)}" }
|
||||
@@ -32,11 +36,13 @@ describe "Display a planting", :js do
|
||||
|
||||
context 'Annual finished' do
|
||||
let(:planting) { FactoryBot.create :annual_planting, planted_at: 100.days.ago, finished: true, finished_at: 1.day.ago }
|
||||
|
||||
it { expect(page).to have_text "Planted #{I18n.l(planting.planted_at)}" }
|
||||
end
|
||||
|
||||
context 'Planting with harvests' do
|
||||
let(:planting) { FactoryBot.create(:harvest_with_planting).planting }
|
||||
|
||||
it { expect(page).to have_text 'Harvest started' }
|
||||
end
|
||||
|
||||
@@ -56,11 +62,13 @@ describe "Display a planting", :js do
|
||||
|
||||
FactoryBot.create :annual_planting, planted_at: 200.days.ago, crop:
|
||||
end
|
||||
|
||||
it { expect(page).to have_text 'First harvest expected' }
|
||||
end
|
||||
|
||||
context 'with quantity' do
|
||||
let(:planting) { FactoryBot.create :planting, quantity: 100 }
|
||||
|
||||
it { expect(find('.plantingfact--quantity')).to have_text '100' }
|
||||
end
|
||||
end
|
||||
@@ -72,12 +80,15 @@ describe "Display a planting", :js do
|
||||
context 'with matching seeds' do
|
||||
let(:seed) { FactoryBot.create :seed, saved_at: 1.month.ago, owner: member }
|
||||
let(:planting) { FactoryBot.create :planting, planted_at: 1.day.ago, crop: seed.crop, owner: member }
|
||||
|
||||
it { expect(page).to have_text 'Is this from one of these plantings? ' }
|
||||
|
||||
describe 'linking to planting' do
|
||||
before do
|
||||
choose "planting_parent_seed_id_#{planting.id}"
|
||||
click_button 'save'
|
||||
end
|
||||
|
||||
it { expect(page).to have_text 'Parent seed' }
|
||||
it { expect(page).to have_link href: planting_path(planting) }
|
||||
end
|
||||
|
||||
@@ -61,14 +61,18 @@ describe "Seeds", :js, :search do
|
||||
visit crop_path(maize)
|
||||
click_link "Save seeds"
|
||||
end
|
||||
|
||||
describe 'no trades' do
|
||||
before { click_button "Save #{maize.name} seeds." }
|
||||
|
||||
it { expect(page).to have_content "nowhere" }
|
||||
it { expect(page).to have_content "Successfully added maize seed to your stash" }
|
||||
it { expect(page).to have_content "maize" }
|
||||
end
|
||||
|
||||
describe 'tradeable' do
|
||||
before { click_button "locally" }
|
||||
|
||||
it { expect(page).to have_content "locally" }
|
||||
it { expect(page).to have_content "Successfully added maize seed to your stash" }
|
||||
it { expect(page).to have_content "maize" }
|
||||
|
||||
@@ -7,6 +7,7 @@ describe "Seeds", :js do
|
||||
context 'signed in' do
|
||||
include_context 'signed in member'
|
||||
before { visit seed_path(seed) }
|
||||
|
||||
subject { page }
|
||||
|
||||
let(:member) { FactoryBot.create :member }
|
||||
@@ -34,12 +35,15 @@ describe "Seeds", :js do
|
||||
it "shows newest photo" do
|
||||
expect(subject).to have_xpath("//img[contains(@src,'#{photos.last.thumbnail_url}')]")
|
||||
end
|
||||
|
||||
it "links to newest photo" do
|
||||
expect(subject).to have_xpath("//a[contains(@href,'#{photo_path(photos.last)}')]")
|
||||
end
|
||||
|
||||
it "does not show oldest photo" do
|
||||
expect(subject).not_to have_xpath("//img[contains(@src,'#{photos.first.thumbnail_url}')]")
|
||||
end
|
||||
|
||||
it "does not link to oldest photo" do
|
||||
expect(subject).not_to have_xpath("//a[contains(@href,'#{photo_path(photos.first)}')]")
|
||||
end
|
||||
|
||||
@@ -15,6 +15,7 @@ shared_examples "append date" do
|
||||
find(".datepicker-days td.day", text: "21").click
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(page).to have_content "Finished" }
|
||||
it { expect(page).to have_content "#{this_month} #{this_year}" }
|
||||
end
|
||||
@@ -25,6 +26,7 @@ shared_examples "append date" do
|
||||
click_link link_text
|
||||
click_link "Confirm without date"
|
||||
end
|
||||
|
||||
it { expect(page).to have_content("Finished") }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +45,7 @@ describe "signin", js: true do
|
||||
conversation = member.send_message(recipient, 'hey there', 'kiaora')
|
||||
visit conversation_path(conversation)
|
||||
end
|
||||
|
||||
it { expect(page).to have_current_path new_member_session_path, ignore_query: true }
|
||||
end
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ describe "timeline", js: true do
|
||||
it { expect(page).to have_link href: planting_path(finished_planting) }
|
||||
it { expect(page).not_to have_link href: planting_path(no_planted_at_planting) }
|
||||
end
|
||||
|
||||
describe 'shows the friends you follow' do
|
||||
it { expect(page).to have_link href: member_path(friend1) }
|
||||
it { expect(page).to have_link href: member_path(friend2) }
|
||||
|
||||
@@ -75,18 +75,23 @@ describe ApplicationHelper do
|
||||
it 'works when :alert' do
|
||||
expect(build_alert_classes(:alert)).to include 'alert-danger'
|
||||
end
|
||||
|
||||
it 'works when :danger' do
|
||||
expect(build_alert_classes(:danger)).to include 'alert-danger'
|
||||
end
|
||||
|
||||
it 'works when :error' do
|
||||
expect(build_alert_classes(:error)).to include 'alert-danger'
|
||||
end
|
||||
|
||||
it 'works when :validation_errors' do
|
||||
expect(build_alert_classes(:validation_errors)).to include 'alert-danger'
|
||||
end
|
||||
|
||||
it 'includes base classes' do
|
||||
expect(build_alert_classes(:danger)).to include 'alert alert-dismissable'
|
||||
end
|
||||
|
||||
it 'does not include danger when info' do
|
||||
expect(build_alert_classes(:info)).not_to include ' alert-danger'
|
||||
end
|
||||
@@ -96,12 +101,15 @@ describe ApplicationHelper do
|
||||
it 'works when :warning' do
|
||||
expect(build_alert_classes(:warning)).to include 'alert-warning'
|
||||
end
|
||||
|
||||
it 'works when :todo' do
|
||||
expect(build_alert_classes(:todo)).to include 'alert-warning'
|
||||
end
|
||||
|
||||
it 'includes base classes' do
|
||||
expect(build_alert_classes(:warning)).to include 'alert alert-dismissable'
|
||||
end
|
||||
|
||||
it 'does not include warning when info' do
|
||||
expect(build_alert_classes(:info)).not_to include ' alert-warning'
|
||||
end
|
||||
@@ -111,12 +119,15 @@ describe ApplicationHelper do
|
||||
it 'works when :notice' do
|
||||
expect(build_alert_classes(:notice)).to include 'alert-success'
|
||||
end
|
||||
|
||||
it 'works when :success' do
|
||||
expect(build_alert_classes(:success)).to include 'alert-success'
|
||||
end
|
||||
|
||||
it 'includes base classes' do
|
||||
expect(build_alert_classes(:success)).to include 'alert alert-dismissable'
|
||||
end
|
||||
|
||||
it 'does not include success when info' do
|
||||
expect(build_alert_classes(:info)).not_to include ' alert-success'
|
||||
end
|
||||
@@ -126,12 +137,15 @@ describe ApplicationHelper do
|
||||
it 'works when :info' do
|
||||
expect(build_alert_classes(:info)).to include 'alert-info'
|
||||
end
|
||||
|
||||
it 'works when blank' do
|
||||
expect(build_alert_classes).to include 'alert-info'
|
||||
end
|
||||
|
||||
it 'includes base classes' do
|
||||
expect(build_alert_classes(:info)).to include 'alert alert-dismissable'
|
||||
end
|
||||
|
||||
it 'does not include info when danger' do
|
||||
expect(build_alert_classes(:danger)).not_to include ' alert-info'
|
||||
end
|
||||
|
||||
@@ -11,38 +11,45 @@ RSpec.describe EventHelper, type: :helper do
|
||||
let(:photo) { FactoryBot.create :photo }
|
||||
|
||||
subject { resolve_model(event) }
|
||||
|
||||
describe 'plantings' do
|
||||
let(:event) { OpenStruct.new(id: planting.id, event_type: 'planting') }
|
||||
|
||||
it { expect(subject).to eq planting }
|
||||
it { expect(event_description(event)).to have_text "planted #{planting.crop.name}" }
|
||||
end
|
||||
|
||||
describe 'harvests' do
|
||||
let(:event) { OpenStruct.new(id: harvest.id, event_type: 'harvest') }
|
||||
|
||||
it { expect(subject).to eq harvest }
|
||||
it { expect(event_description(event)).to have_text "harvested" }
|
||||
end
|
||||
|
||||
describe 'seeds' do
|
||||
let(:event) { OpenStruct.new(id: seed.id, event_type: 'seed') }
|
||||
|
||||
it { expect(subject).to eq seed }
|
||||
it { expect(event_description(event)).to have_text "saved #{seed.crop.name} seeds" }
|
||||
end
|
||||
|
||||
describe 'posts' do
|
||||
let(:event) { OpenStruct.new(id: post.id, event_type: 'post') }
|
||||
|
||||
it { expect(subject).to eq post }
|
||||
it { expect(event_description(event)).to have_text 'wrote a post' }
|
||||
end
|
||||
|
||||
describe 'comments' do
|
||||
let(:event) { OpenStruct.new(id: comment.id, event_type: 'comment') }
|
||||
|
||||
it { expect(subject).to eq comment }
|
||||
it { expect(event_description(event)).to have_text 'commented on' }
|
||||
end
|
||||
|
||||
describe 'photos' do
|
||||
let(:event) { OpenStruct.new(id: photo.id, event_type: 'photo') }
|
||||
|
||||
it { expect(subject).to eq photo }
|
||||
it { expect(event_description(event)).to have_text "took a photo" }
|
||||
end
|
||||
|
||||
@@ -52,7 +52,9 @@ describe PhotosHelper do
|
||||
|
||||
describe "has a flickr photo" do
|
||||
let(:garden_photo) { FactoryBot.create(:photo, owner: garden.owner, source: 'flickr') }
|
||||
|
||||
before { garden.photos << garden_photo }
|
||||
|
||||
it { is_expected.to eq garden_photo.fullsize_url }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,12 +18,14 @@ describe Ability do
|
||||
recipient: FactoryBot.create(:member))
|
||||
ability.should_not be_able_to(:read, notification)
|
||||
end
|
||||
|
||||
it "member can't send messages to themself" do
|
||||
ability.should_not be_able_to(:create,
|
||||
FactoryBot.create(:notification,
|
||||
recipient: member,
|
||||
sender: member))
|
||||
end
|
||||
|
||||
it "member can send messages to someone else" do
|
||||
ability.should be_able_to(:create,
|
||||
FactoryBot.create(:notification,
|
||||
@@ -64,9 +66,11 @@ describe Ability do
|
||||
it "can create crops" do
|
||||
ability.should be_able_to(:create, Crop)
|
||||
end
|
||||
|
||||
it "can update crops" do
|
||||
ability.should be_able_to(:update, crop)
|
||||
end
|
||||
|
||||
it "can destroy crops" do
|
||||
ability.should be_able_to(:destroy, crop)
|
||||
end
|
||||
@@ -80,6 +84,7 @@ describe Ability do
|
||||
it "can read plant parts" do
|
||||
ability.should be_able_to(:read, plant_part)
|
||||
end
|
||||
|
||||
it "can't manage plant parts" do
|
||||
ability.should_not be_able_to(:create, PlantPart)
|
||||
ability.should_not be_able_to(:update, plant_part)
|
||||
@@ -97,6 +102,7 @@ describe Ability do
|
||||
it "can read plant_part details" do
|
||||
ability.should be_able_to(:read, plant_part)
|
||||
end
|
||||
|
||||
it "can manage plant_part details" do
|
||||
ability.should be_able_to(:create, PlantPart)
|
||||
ability.should be_able_to(:update, plant_part)
|
||||
|
||||
@@ -37,7 +37,7 @@ describe Comment do
|
||||
@p = FactoryBot.create(:post, author: @m)
|
||||
expect do
|
||||
FactoryBot.create(:comment, post: @p, author: @m)
|
||||
end.to change(Notification, :count).by(0)
|
||||
end.not_to change(Notification, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ describe Crop do
|
||||
before { planting.photos << photo }
|
||||
|
||||
it { expect(crop.default_photo).to eq photo }
|
||||
|
||||
include_examples 'has default photo'
|
||||
end
|
||||
|
||||
@@ -162,6 +163,7 @@ describe Crop do
|
||||
before { harvest.photos << photo }
|
||||
|
||||
it { expect(crop.default_photo).to eq photo }
|
||||
|
||||
include_examples 'has default photo'
|
||||
|
||||
context 'and planting photo' do
|
||||
@@ -301,6 +303,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
|
||||
|
||||
@@ -138,6 +138,7 @@ describe Garden do
|
||||
described_class.active.should include active
|
||||
described_class.active.should_not include inactive
|
||||
end
|
||||
|
||||
it 'includes inactive garden in inactive scope' do
|
||||
described_class.inactive.should include inactive
|
||||
described_class.inactive.should_not include active
|
||||
|
||||
@@ -138,21 +138,25 @@ describe Member do
|
||||
member.should_not be_valid
|
||||
member.errors[:login_name].should include("should be between 2 and 25 characters long")
|
||||
end
|
||||
|
||||
it "doesn't allow really long names" do
|
||||
member = FactoryBot.build(:invalid_member_longname)
|
||||
member.should_not be_valid
|
||||
member.errors[:login_name].should include("should be between 2 and 25 characters long")
|
||||
end
|
||||
|
||||
it "doesn't allow spaces in names" do
|
||||
member = FactoryBot.build(:invalid_member_spaces)
|
||||
member.should_not be_valid
|
||||
member.errors[:login_name].should include("may only include letters, numbers, or underscores")
|
||||
end
|
||||
|
||||
it "doesn't allow other chars in names" do
|
||||
member = FactoryBot.build(:invalid_member_badchars)
|
||||
member.should_not be_valid
|
||||
member.errors[:login_name].should include("may only include letters, numbers, or underscores")
|
||||
end
|
||||
|
||||
it "doesn't allow reserved names" do
|
||||
member = FactoryBot.build(:invalid_member_badname)
|
||||
member.should_not be_valid
|
||||
@@ -165,10 +169,12 @@ describe Member do
|
||||
member = FactoryBot.build(:valid_member_alphanumeric)
|
||||
member.should be_valid
|
||||
end
|
||||
|
||||
it "allows uppercase chars in names" do
|
||||
member = FactoryBot.build(:valid_member_uppercase)
|
||||
member.should be_valid
|
||||
end
|
||||
|
||||
it "allows underscores in names" do
|
||||
member = FactoryBot.build(:valid_member_underscore)
|
||||
member.should be_valid
|
||||
|
||||
@@ -27,13 +27,16 @@ describe Photo do
|
||||
|
||||
describe 'with a second older photo' do
|
||||
let(:old_photo) { FactoryBot.create(:photo, owner: member, created_at: 1.year.ago, date_taken: 2.years.ago) }
|
||||
|
||||
# Add an old photo
|
||||
before { planting.photos << old_photo }
|
||||
|
||||
it { expect(planting.default_photo).to eq photo }
|
||||
it { expect(planting.crop.default_photo).to eq photo }
|
||||
|
||||
describe 'and someone likes the old photo' do
|
||||
before { FactoryBot.create :like, likeable: old_photo }
|
||||
|
||||
it { expect(planting.default_photo).to eq old_photo }
|
||||
it { expect(planting.crop.default_photo).to eq old_photo }
|
||||
end
|
||||
@@ -42,6 +45,7 @@ describe Photo do
|
||||
|
||||
describe 'to a harvest' do
|
||||
let(:crop) { harvest.crop }
|
||||
|
||||
before { harvest.photos << photo }
|
||||
|
||||
it { expect(harvest.photos).to eq [photo] }
|
||||
@@ -247,6 +251,7 @@ describe Photo do
|
||||
it "finds just one" do
|
||||
expect(described_class.search.count).to eq 1
|
||||
end
|
||||
|
||||
it "finds the matching photo" do
|
||||
expect(described_class.search).to include photo
|
||||
end
|
||||
@@ -259,6 +264,7 @@ describe Photo do
|
||||
it "finds photos by owner in search index" do
|
||||
expect(described_class.search(where: { owner_id: planting.owner_id })).to include photo
|
||||
end
|
||||
|
||||
it "finds photos by crop in search index" do
|
||||
expect(described_class.search(where: { crops: planting.crop.id })).to include photo
|
||||
end
|
||||
|
||||
@@ -140,6 +140,7 @@ describe Planting do
|
||||
end
|
||||
|
||||
it { expect(crop.median_days_to_first_harvest).to eq(20) }
|
||||
|
||||
describe 'sets median time to harvest' do
|
||||
let(:planting) { FactoryBot.create :planting, crop:, planted_at: Time.zone.today }
|
||||
|
||||
@@ -211,7 +212,9 @@ describe Planting do
|
||||
|
||||
describe 'planting perennial' do
|
||||
let(:crop) { FactoryBot.create(:crop, name: 'feijoa', perennial: true) }
|
||||
|
||||
it { expect(planting.perennial?).to be true }
|
||||
|
||||
describe 'no harvest to predict from' do
|
||||
it { expect(planting.harvest_months).to eq({}) }
|
||||
end
|
||||
@@ -222,6 +225,7 @@ describe Planting do
|
||||
FactoryBot.create :harvest, planting: planting, crop: crop, harvested_at: '18 June 2019'
|
||||
FactoryBot.create_list :harvest, 4, planting:, crop:, harvested_at: '18 August 2019'
|
||||
end
|
||||
|
||||
it { expect(planting.harvest_months).to eq(5 => 1, 6 => 1, 8 => 4) }
|
||||
end
|
||||
|
||||
@@ -252,9 +256,11 @@ describe Planting do
|
||||
FactoryBot.create_list :harvest, 4, planting: faraway_planting, crop:,
|
||||
harvested_at: '18 December 2006'
|
||||
end
|
||||
|
||||
it { expect(planting.harvest_months).to eq(5 => 1, 6 => 1, 8 => 4) }
|
||||
end
|
||||
end
|
||||
|
||||
it 'has an owner' do
|
||||
planting.owner.should be_an_instance_of Member
|
||||
end
|
||||
@@ -277,10 +283,12 @@ describe Planting do
|
||||
planting = FactoryBot.create :planting, planted_at: Time.zone.today + 1
|
||||
expect(planting.planted?).to be(false)
|
||||
end
|
||||
|
||||
it "is false for never planted" do
|
||||
planting = FactoryBot.create :planting, planted_at: nil
|
||||
expect(planting.planted?).to be(false)
|
||||
end
|
||||
|
||||
it "is true for past plantings" do
|
||||
planting = FactoryBot.create :planting, planted_at: Time.zone.today - 1
|
||||
expect(planting.planted?).to be(true)
|
||||
@@ -518,9 +526,11 @@ describe Planting do
|
||||
it "planting has a parent seed" do
|
||||
expect(planting.parent_seed).to eq(parent_seed)
|
||||
end
|
||||
|
||||
it "seed has a child planting" do
|
||||
expect(parent_seed.child_plantings).to eq [planting]
|
||||
end
|
||||
|
||||
describe 'grandchildren' do
|
||||
let(:grandchild_seed) { FactoryBot.create :seed, parent_planting: planting }
|
||||
|
||||
@@ -537,6 +547,7 @@ describe Planting do
|
||||
let!(:finished_planting) do
|
||||
FactoryBot.create :finished_planting, owner: member, garden: member.gardens.first
|
||||
end
|
||||
|
||||
it { expect(member.plantings.active).to include(planting) }
|
||||
it { expect(member.plantings.active).not_to include(finished_planting) }
|
||||
end
|
||||
@@ -547,6 +558,7 @@ describe Planting do
|
||||
let!(:planting) { FactoryBot.create :planting, :reindex }
|
||||
|
||||
before { described_class.reindex }
|
||||
|
||||
subject { described_class.homepage_records(100) }
|
||||
|
||||
it { expect(subject.count).to eq 2 }
|
||||
|
||||
@@ -128,7 +128,7 @@ describe Post do
|
||||
it "doesn't send notifications if you mention yourself" do
|
||||
expect do
|
||||
FactoryBot.create(:post, author: member, body: "@#{member}")
|
||||
end.to change(Notification, :count).by(0)
|
||||
end.not_to change(Notification, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -169,6 +169,7 @@ describe Seed do
|
||||
it "seed has a parent planting" do
|
||||
expect(seed.parent_planting).to eq(parent_planting)
|
||||
end
|
||||
|
||||
it "planting has a child seed" do
|
||||
expect(parent_planting.child_seeds).to eq [seed]
|
||||
end
|
||||
@@ -204,6 +205,7 @@ describe Seed do
|
||||
let!(:untradable_seed) { FactoryBot.create :untradable_seed, :reindex }
|
||||
|
||||
before { described_class.reindex }
|
||||
|
||||
subject { described_class.homepage_records(100) }
|
||||
|
||||
it { expect(subject.count).to eq 1 }
|
||||
|
||||
@@ -35,6 +35,7 @@ describe MembersController do
|
||||
it "routes to harvests#index" do
|
||||
get("/members/name/harvests").should route_to("harvests#index", member_slug: 'name')
|
||||
end
|
||||
|
||||
it "routes to plantings#index" do
|
||||
get("/members/name/plantings").should route_to("plantings#index", member_slug: 'name')
|
||||
end
|
||||
|
||||
@@ -14,6 +14,7 @@ RSpec.describe CropSearchService, type: :service do
|
||||
let!(:taewa) { FactoryBot.create(:crop, name: 'taewa') }
|
||||
let!(:zucchini) { FactoryBot.create(:crop, name: 'zucchini') }
|
||||
let!(:broccoli) { FactoryBot.create(:crop, name: 'broccoli') }
|
||||
|
||||
before do
|
||||
# Alternate name
|
||||
FactoryBot.create :alternate_name, name: 'fungus', crop: mushroom
|
||||
@@ -55,18 +56,23 @@ RSpec.describe CropSearchService, type: :service do
|
||||
|
||||
describe 'biased to higher planting counts' do
|
||||
subject { search('mushroom') }
|
||||
|
||||
before do
|
||||
# Having plantings should bring these crops to the top of the search results
|
||||
FactoryBot.create_list :planting, 10, crop: white
|
||||
FactoryBot.create_list :planting, 4, crop: shitake
|
||||
Crop.reindex
|
||||
end
|
||||
|
||||
it { expect(subject.first).to eq 'white mushroom' }
|
||||
it { expect(subject.second).to eq 'shitake mushroom' }
|
||||
end
|
||||
|
||||
describe "biased to crops you've planted" do
|
||||
subject { described_class.search('mushroom', current_member: owner).map(&:name) }
|
||||
|
||||
let(:owner) { FactoryBot.create :member }
|
||||
|
||||
before do
|
||||
FactoryBot.create_list :planting, 10, crop: brown
|
||||
FactoryBot.create :planting, crop: oyster, owner: owner
|
||||
@@ -74,6 +80,7 @@ RSpec.describe CropSearchService, type: :service do
|
||||
FactoryBot.create :planting, crop: shitake, owner: owner
|
||||
Crop.reindex
|
||||
end
|
||||
|
||||
it { expect(subject.first).to eq oyster.name }
|
||||
it { expect(subject.second).to eq shitake.name }
|
||||
end
|
||||
|
||||
@@ -14,7 +14,9 @@ describe TimelineService do
|
||||
|
||||
describe 'a friend you followed' do
|
||||
before { friend.followers << member }
|
||||
|
||||
subject { TimelineService.followed_query(member) }
|
||||
|
||||
it { expect(subject.first.id).to eq friend_planting.id }
|
||||
it { expect(subject.first.event_type).to eq 'planting' }
|
||||
it { expect(subject.second.id).to eq friend_harvest.id }
|
||||
|
||||
@@ -76,6 +76,7 @@ describe 'devise/registrations/edit.html.haml', type: "view" do
|
||||
it 'has a link to twitter profile' do
|
||||
assert_select "a", href: "http://twitter.com/#{@twitter_auth.name}"
|
||||
end
|
||||
|
||||
it 'has a link to disconnect' do
|
||||
render
|
||||
assert_select "a", href: @twitter_auth, text: "Disconnect"
|
||||
@@ -98,6 +99,7 @@ describe 'devise/registrations/edit.html.haml', type: "view" do
|
||||
it 'has a link to flickr photostream' do
|
||||
assert_select "a", href: "http://flickr.com/photos/#{@flickr_auth.uid}"
|
||||
end
|
||||
|
||||
it 'has a link to disconnect' do
|
||||
render
|
||||
assert_select "a", href: @flickr_auth, text: "Disconnect"
|
||||
|
||||
@@ -6,6 +6,7 @@ describe "forums/index" do
|
||||
let(:admin) { FactoryBot.create(:admin_member) }
|
||||
let(:forum1) { FactoryBot.create(:forum) }
|
||||
let(:forum2) { FactoryBot.create(:forum) }
|
||||
|
||||
before do
|
||||
controller.stub(:current_user) { admin }
|
||||
assign(:forums, [forum1, forum2])
|
||||
@@ -24,6 +25,7 @@ describe "forums/index" do
|
||||
context "posts" do
|
||||
let!(:post) { FactoryBot.create(:forum_post, forum: forum1) }
|
||||
let!(:comment) { FactoryBot.create(:comment, post:) }
|
||||
|
||||
before { render }
|
||||
|
||||
describe "displays posts" do
|
||||
|
||||
@@ -18,6 +18,7 @@ describe 'harvests/index.rss.haml', :search do
|
||||
|
||||
context 'all harvests' do
|
||||
before { render }
|
||||
|
||||
it 'shows RSS feed title' do
|
||||
expect(rendered).to have_content "Recent harvests from all members"
|
||||
end
|
||||
@@ -32,6 +33,7 @@ describe 'harvests/index.rss.haml', :search do
|
||||
assign(:crop, @tomato)
|
||||
render
|
||||
end
|
||||
|
||||
it "displays crop's name in title" do
|
||||
expect(rendered).to have_content @tomato.name
|
||||
end
|
||||
|
||||
@@ -5,6 +5,7 @@ require 'rails_helper'
|
||||
describe 'home/_seeds.html.haml', search: true, type: "view" do
|
||||
let!(:seed) { FactoryBot.create(:tradable_seed, owner:) }
|
||||
let(:owner) { FactoryBot.create(:london_member) }
|
||||
|
||||
before do
|
||||
Seed.searchkick_index.refresh
|
||||
render
|
||||
|
||||
@@ -64,15 +64,19 @@ describe 'layouts/_header.html.haml', type: "view" do
|
||||
it 'has member login name' do
|
||||
rendered.should have_content @member.login_name.to_s
|
||||
end
|
||||
|
||||
it "shows link to member's gardens" do
|
||||
assert_select("a[href='#{member_gardens_path(@member)}']", "Gardens")
|
||||
end
|
||||
|
||||
it "shows link to member's plantings" do
|
||||
assert_select("a[href='#{member_plantings_path(@member)}']", "Plantings")
|
||||
end
|
||||
|
||||
it "shows link to member's seeds" do
|
||||
assert_select("a[href='#{member_seeds_path(@member)}']", "Seeds")
|
||||
end
|
||||
|
||||
it "shows link to member's posts" do
|
||||
assert_select("a[href='#{member_posts_path(@member)}']", "Posts")
|
||||
end
|
||||
|
||||
@@ -24,6 +24,7 @@ describe "plantings/show" do
|
||||
|
||||
describe "shows the sunniness" do
|
||||
before { render }
|
||||
|
||||
it { expect(rendered).to have_content 'Planted in' }
|
||||
it { expect(rendered).to have_content 'sun' }
|
||||
end
|
||||
@@ -34,6 +35,7 @@ describe "plantings/show" do
|
||||
|
||||
describe "shows planted_from" do
|
||||
before { render }
|
||||
|
||||
it { expect(rendered).to have_content 'Grown from' }
|
||||
it { expect(rendered).to have_content 'cutting' }
|
||||
end
|
||||
@@ -43,6 +45,7 @@ describe "plantings/show" do
|
||||
planting.update(planted_from: '')
|
||||
render
|
||||
end
|
||||
|
||||
it { expect(rendered).not_to have_content 'Planted from' }
|
||||
end
|
||||
end
|
||||
@@ -59,6 +62,7 @@ describe "plantings/show" do
|
||||
|
||||
describe "shows a link to add photos" do
|
||||
before { render }
|
||||
|
||||
it { expect(rendered).to have_content "Add photo" }
|
||||
end
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ describe "posts/new" do
|
||||
it 'tells the user what forum it will be posted in' do
|
||||
expect(rendered).to have_content "This post will be posted in the forum #{forum.name}"
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_link forum.name }
|
||||
|
||||
describe "asks what's going on generally" do
|
||||
|
||||
@@ -17,6 +17,7 @@ describe "scientific_names/edit" do
|
||||
it "shows the creator" do
|
||||
expect(rendered).to have_content "Added by #{member} less than a minute ago."
|
||||
end
|
||||
|
||||
it { expect(rendered).to have_link member_path(member) }
|
||||
|
||||
it "renders the edit scientific_name form" do
|
||||
|
||||
@@ -24,6 +24,7 @@ describe 'seeds/index.rss.haml', :search do
|
||||
context 'all seeds' do
|
||||
let!(:seed) { FactoryBot.create(:seed) }
|
||||
let!(:tradable) { FactoryBot.create(:tradable_seed) }
|
||||
|
||||
before do
|
||||
Seed.searchkick_index.refresh
|
||||
assign(:seeds, Seed.search(load: false))
|
||||
|
||||
Reference in New Issue
Block a user