Merge remote-tracking branch 'origin/charts' into charts

This commit is contained in:
Brenda Wallace
2018-01-11 08:30:38 +13:00
30 changed files with 82 additions and 1 deletions

View File

@@ -22,7 +22,6 @@ else
abort %(
Couldn't determine your GitHub username, and not in a Travis PR build
Please set it using
git config --add github.user [username]
)
end

View File

@@ -21,6 +21,7 @@ describe AccountTypesController do
describe '#index' do
let!(:aaa) { FactoryBot.create :account_type, name: 'aaa' }
let!(:zzz) { FactoryBot.create :account_type, name: 'zzz' }
before { get :index }
it { is_expected.to be_success }
it { expect(assigns[:account_types].first).to eql(aaa) }

View File

@@ -3,6 +3,7 @@ require 'rails_helper'
describe CommentsController do
subject { response }
let(:member) { FactoryBot.create(:member) }
before(:each) do
sign_in member
controller.stub(:current_member) { member }
@@ -16,6 +17,7 @@ describe CommentsController do
describe "GET RSS feed" do
let!(:first_comment) { FactoryBot.create :comment, created_at: 10.days.ago }
let!(:last_comment) { FactoryBot.create :comment, created_at: 4.minutes.ago }
describe "returns an RSS feed" do
before { get :index, format: "rss" }
it { is_expected.to be_success }
@@ -36,6 +38,7 @@ describe CommentsController do
end
let(:old_comment) { FactoryBot.create(:comment, post: post) }
it "assigns the old comments as @comments" do
assigns(:comments).should eq [old_comment]
end
@@ -49,11 +52,13 @@ describe CommentsController do
describe "GET edit" do
let(:post) { FactoryBot.create(:post) }
before { get :edit, id: comment.to_param }
describe "my comment" do
let!(:comment) { FactoryBot.create :comment, author: member, post: post }
let!(:old_comment) { FactoryBot.create(:comment, post: post, created_at: Time.zone.yesterday) }
it "assigns previous comments as @comments" do
expect(assigns(:comments)).to eq([comment, old_comment])
end
@@ -61,6 +66,7 @@ describe CommentsController do
describe "not my comment" do
let(:comment) { FactoryBot.create :comment, post: post }
it { expect(response).not_to be_success }
end
end
@@ -70,12 +76,14 @@ describe CommentsController do
describe "my comment" do
let(:comment) { FactoryBot.create :comment, author: member }
it "redirects to the comment's post" do
expect(response).to redirect_to(comment.post)
end
end
describe "not my comment" do
let(:comment) { FactoryBot.create :comment }
it { expect(response).not_to be_success }
end
describe "attempting to change post_id" do
@@ -83,6 +91,7 @@ describe CommentsController do
let(:other_post) { FactoryBot.create :post, subject: 'the other post' }
let(:valid_attributes) { { post_id: other_post.id, body: "kōrero" } }
let(:comment) { FactoryBot.create :comment, author: member, post: post }
it "does not change post_id" do
comment.reload
expect(comment.post_id).to eq(post.id)
@@ -95,6 +104,7 @@ describe CommentsController do
describe "my comment" do
let(:comment) { FactoryBot.create :comment, author: member }
it "redirects to the post the comment was on" do
expect(response).to redirect_to(comment.post)
end
@@ -102,6 +112,7 @@ describe CommentsController do
describe "not my comment" do
let(:comment) { FactoryBot.create :comment }
it { expect(response).not_to be_success }
end
end

View File

@@ -6,6 +6,7 @@ RSpec.describe GardensController, type: :controller do
context "when not signed in" do
let(:garden) { double('garden') }
describe 'GET new' do
before { get :new, id: garden.to_param }
it { expect(response).to redirect_to(new_member_session_path) }
@@ -45,6 +46,7 @@ RSpec.describe GardensController, type: :controller do
describe "for another member's garden" do
let(:not_my_garden) { double('garden') }
before do
expect(Garden).to receive(:find).and_return(:not_my_garden)
expect(not_my_garden).not_to receive(:save)

View File

@@ -45,6 +45,7 @@ describe HarvestsController do
describe "GET show" do
let(:harvest) { Harvest.create! valid_attributes }
describe "assigns the requested harvest as @harvest" do
before { get :show, id: harvest.to_param }
it { expect(assigns(:harvest)).to eq(harvest) }
@@ -65,6 +66,7 @@ describe HarvestsController do
describe "GET edit" do
let(:harvest) { Harvest.create! valid_attributes }
describe "assigns the requested harvest as @harvest" do
before { get :edit, id: harvest.to_param }
it { expect(assigns(:harvest)).to eq(harvest) }
@@ -92,6 +94,7 @@ describe HarvestsController do
describe "links to planting" do
let(:planting) { FactoryBot.create(:planting, owner_id: member.id, garden: member.gardens.first) }
before { post :create, harvest: valid_attributes.merge(planting_id: planting.id) }
it { expect(Harvest.last.planting.id).to eq(planting.id) }
end
@@ -170,6 +173,7 @@ describe HarvestsController do
describe "not my planting" do
let(:not_my_planting) { FactoryBot.create(:planting) }
let(:harvest) { FactoryBot.create(:harvest) }
describe "does not save planting_id" do
before do
put :update, id: harvest.to_param,

View File

@@ -35,6 +35,7 @@ describe LikesController do
describe "Deleting someone else's like" do
let(:like) { FactoryBot.create :like }
it { expect(response.code).to eq('403') }
it { JSON.parse(response.body)["error"] == "Unable to like" }
end

View File

@@ -26,6 +26,7 @@ describe PhotoAssociationsController do
describe "another member's harvest from another member's photo" do
let(:harvest) { FactoryBot.create :harvest }
let(:photo) { FactoryBot.create :photo }
it do
expect do
begin

View File

@@ -73,6 +73,7 @@ describe PhotosController do
let(:planting) { FactoryBot.create(:planting, garden: garden, owner: member) }
let(:harvest) { FactoryBot.create(:harvest, owner: member) }
let(:photo) { FactoryBot.create(:photo, owner: member) }
describe "with valid params" do
before { controller.stub(:current_member) { member } }
it "attaches the photo to a planting" do
@@ -113,6 +114,7 @@ describe PhotosController do
describe "for the second time" do
let(:planting) { FactoryBot.create :planting, owner: member }
it "does not add a photo twice" do
expect do
post :create, photo: { flickr_photo_id: 1 }, id: planting.id, type: 'planting'
@@ -142,6 +144,7 @@ describe PhotosController do
describe "with mismatched owners" do
let(:photo) { FactoryBot.create(:photo) }
it "does not create the planting/photo link" do
# members will be auto-created, and different
another_planting = FactoryBot.create(:planting)

View File

@@ -39,6 +39,7 @@ describe PlantingsController do
describe "GET new" do
describe "picks up crop from params" do
let(:crop) { FactoryBot.create(:crop) }
before { get :new, crop_id: crop.id }
it { expect(assigns(:crop)).to eq(crop) }
end
@@ -50,6 +51,7 @@ describe PlantingsController do
describe "picks up member's garden from params" do
let(:garden) { FactoryBot.create(:garden, owner: member) }
before { get :new, garden_id: garden.id }
it { expect(assigns(:garden)).to eq(garden) }
end
@@ -57,6 +59,7 @@ describe PlantingsController do
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, garden_id: garden.id }
it { expect(assigns(:garden)).not_to eq(garden) }
end
@@ -64,6 +67,7 @@ describe PlantingsController do
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, crop_id: crop.id }
it { expect(assigns(:crop)).not_to eq(crop) }
end
@@ -71,6 +75,7 @@ describe PlantingsController do
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, crop_id: crop.id }
it { expect(assigns(:crop)).not_to eq(crop) }
end

View File

@@ -24,6 +24,7 @@ describe ShopController do
describe "assigns @order as current_order if there is one" do
let(:member) { FactoryBot.create(:member) }
let!(:order) { FactoryBot.create(:order, member: member) }
before do
sign_in member
get :index, {}

View File

@@ -205,6 +205,7 @@ feature "crop detail page", js: true do
planted_at: 100.days.ago,
finished_at: 1.day.ago)
end
context 'crop is an annual' do
let(:crop) { FactoryBot.create(:annual_crop) }
@@ -258,16 +259,19 @@ feature "crop detail page", js: true do
before { visit crop_path(crop) }
context 'crop is an annual' do
let(:crop) { FactoryBot.create :annual_crop }
it { expect(page).to have_text 'annual crop (living and reproducing in a single year or less)' }
it { expect(page).not_to have_text 'perennial crop (living more than two years)' }
end
context 'crop is perennial' do
let(:crop) { FactoryBot.create :perennial_crop }
it { expect(page).to have_text 'perennial crop (living more than two years)' }
it { expect(page).not_to have_text 'annual crop (living and reproducing in a single year or less)' }
end
context 'crop perennial value is null' do
let(:crop) { FactoryBot.create :crop, perennial: nil }
it { expect(page).not_to have_text 'perennial crop (living more than two years)' }
it { expect(page).not_to have_text 'annual crop (living and reproducing in a single year or less)' }
end

View File

@@ -3,6 +3,7 @@ require 'rails_helper'
feature "Crop - " do
let(:member) { create :member }
let!(:requested_crop) { create :crop, requester: member, approval_status: 'pending', name: 'puha for dinner' }
background do
login_as member
visit requested_crops_path

View File

@@ -88,6 +88,7 @@ feature "Planting a crop", js: true do
describe "Making a planting inactive from garden show" do
let(:path) { garden_path garden }
let(:link_text) { "Mark as finished" }
it_behaves_like "append date"
end

View File

@@ -12,6 +12,7 @@ feature "member deletion" do
let!(:secondgarden) { FactoryBot.create(:garden, owner: member) }
let!(:order) { FactoryBot.create(:order, member: member, completed_at: Time.zone.now) }
let(:admin) { FactoryBot.create(:admin_member) }
background do
login_as(member)
visit member_path(other_member)

View File

@@ -270,6 +270,7 @@ feature "Planting a crop", :js, :elasticsearch do
describe "Marking a planting as finished from the show page" do
let(:path) { planting_path(planting) }
let(:link_text) { "Mark as finished" }
it_behaves_like "append date"
end

View File

@@ -19,12 +19,14 @@ feature "Seeds", :js do
context 'has one photo' do
before { seed.photos = [photo] }
let!(:photo) { FactoryBot.create :photo, title: 'hello photo' }
it { is_expected.to have_xpath("//img[contains(@src,'#{photo.thumbnail_url}')]") }
it { is_expected.to have_xpath("//a[contains(@href,'#{photo_path(photo)}')]") }
end
context 'has 50 photos' do
before { seed.photos = photos }
let!(:photos) { FactoryBot.create_list :photo, 50 }
it "shows newest photo" do
is_expected.to have_xpath("//img[contains(@src,'#{photos.last.thumbnail_url}')]")
end

View File

@@ -30,6 +30,7 @@ feature "signout" do
end
let(:path) {}
describe 'after signout, redirect to signin page if page needs authentication' do
include_examples "sign-in redirects", "/plantings/new"
include_examples "sign-in redirects", "/harvests/new"

View File

@@ -82,36 +82,43 @@ describe Crop do
context 'not a url' do
let(:wikipedia_url) { 'this is not valid' }
it { expect(subject).not_to be_valid }
end
context 'http url' do
let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage' }
it { expect(subject).to be_valid }
end
context 'with ssl' do
let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/SomePage' }
it { expect(subject).to be_valid }
end
context 'with utf8 macrons' do
let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/Māori' }
it { expect(subject).to be_valid }
end
context 'urlencoded' do
let(:wikipedia_url) { 'https://en.wikipedia.org/wiki/M%C4%81ori' }
it { expect(subject).to be_valid }
end
context 'with new lines in url' do
let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage\n\nBrendaRocks' }
it { expect(subject).not_to be_valid }
end
context "with script tags in url" do
let(:wikipedia_url) { 'http://en.wikipedia.org/wiki/SomePage<script>alert(\'BrendaRocks\')</script>' }
it { expect(subject).not_to be_valid }
end
end
@@ -330,6 +337,7 @@ describe Crop do
let(:h2) { FactoryBot.create(:harvest, crop: maize, plant_part: pp2) }
let!(:crop) { FactoryBot.create(:crop) }
let!(:harvest) { FactoryBot.create(:harvest, crop: crop) }
it "has harvests" do
expect(crop.harvests).to eq [harvest]
end

View File

@@ -432,6 +432,7 @@ describe 'member' do
context 'member deleted' do
let(:member) { FactoryBot.create(:member) }
context 'queries a scope' do
before { member.destroy }
it { expect(Member.all).not_to include(member) }
@@ -450,10 +451,12 @@ describe 'member' do
context "deleted admin member" do
let(:member) { FactoryBot.create(:admin_member) }
before { member.destroy }
context 'crop creator' do
let!(:crop) { FactoryBot.create(:crop, creator: member) }
it "leaves crops behind, reassigned to cropbot" do
expect(Crop.all).to include(crop)
end
@@ -461,6 +464,7 @@ describe 'member' do
context 'forum owners' do
let!(:forum) { FactoryBot.create(:forum, owner: member) }
it "leaves forums behind, reassigned to ex_admin" do
expect(forum.owner).to eq(member)
end

View File

@@ -3,6 +3,7 @@ require 'rails_helper'
describe Photo do
let(:photo) { FactoryBot.create(:photo, owner: member) }
let(:member) { FactoryBot.create(:member) }
describe 'add/delete functionality' do
let(:planting) { FactoryBot.create(:planting) }
let(:harvest) { FactoryBot.create(:harvest) }

View File

@@ -13,6 +13,7 @@ describe Planting do
context 'no predications data yet' do
describe 'planting planted, not finished' do
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: nil, finished: false }
it { expect(planting.crop.median_lifespan).to eq(nil) }
it { expect(planting.expected_lifespan).to eq(nil) }
it { expect(planting.days_since_planted).to eq(30) }
@@ -20,6 +21,7 @@ describe Planting do
end
describe 'planting not planted yet' do
let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: nil, finished: false }
it { expect(planting.crop.median_lifespan).to eq(nil) }
it { expect(planting.expected_lifespan).to eq(nil) }
it { expect(planting.days_since_planted).to eq(nil) }
@@ -27,6 +29,7 @@ describe Planting do
end
describe 'planting finished, no planted_at' do
let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: 1.day.ago, finished: true }
it { expect(planting.crop.median_lifespan).to eq(nil) }
it { expect(planting.expected_lifespan).to eq(nil) }
it { expect(planting.days_since_planted).to eq(nil) }
@@ -34,6 +37,7 @@ describe Planting do
end
describe 'planting all finished' do
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: 1.day.ago, finished: true }
it { expect(planting.crop.median_lifespan).to eq(nil) }
it { expect(planting.expected_lifespan).to eq(29) }
it { expect(planting.days_since_planted).to eq(30) }
@@ -63,16 +67,19 @@ describe Planting do
describe 'planting not planted yet' do
let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: nil }
it { expect(planting.percentage_grown).to eq nil }
end
describe 'planting finished 10 days, but was never planted' do
let(:planting) { FactoryBot.create :planting, planted_at: nil, finished_at: 10.days.ago }
it { expect(planting.percentage_grown).to eq nil }
end
describe 'planted 30 days ago, finished 10 days ago' do
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: 10.days.ago }
it { expect(planting.days_since_planted).to eq 30 }
it { expect(planting.percentage_grown).to eq 100 }
end
@@ -82,6 +89,7 @@ describe Planting do
describe 'planting first harvest preductions' do
context 'no data' do
let(:planting) { FactoryBot.create :planting }
it { expect(planting.crop.median_days_to_first_harvest).to eq(nil) }
it { expect(planting.crop.median_days_to_last_harvest).to eq(nil) }
it { expect(planting.days_to_first_harvest).to eq(nil) }
@@ -114,11 +122,13 @@ describe Planting do
planting.crop.update_harvest_medians
end
let(:planting) { FactoryBot.create :planting }
it { expect(planting.days_to_first_harvest).to eq(nil) }
it { expect(planting.days_to_last_harvest).to eq(nil) }
end
describe 'planting has first harvest' do
let(:planting) { FactoryBot.create :planting, planted_at: 100.days.ago }
before do
FactoryBot.create(:harvest,
planting: planting,
@@ -134,6 +144,7 @@ describe Planting do
end
describe 'planting has last harvest' do
let(:planting) { FactoryBot.create :planting, planted_at: 100.days.ago, finished_at: 1.day.ago, finished: true }
before do
FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 90.days.ago
FactoryBot.create :harvest, planting: planting, crop: planting.crop, harvested_at: 10.days.ago

View File

@@ -2,6 +2,7 @@ require 'rails_helper'
describe Post do
let(:member) { FactoryBot.create(:member) }
it_behaves_like "it is likeable"
it "should have a slug" do

View File

@@ -19,6 +19,7 @@ describe Role do
describe '.crop_wranglers' do
let!(:crop_wranglers) { FactoryBot.create_list(:crop_wrangling_member, 3) }
it 'return the crop wranglers that are members of that role' do
expect(Role.crop_wranglers).to match_array(crop_wranglers)
end
@@ -26,6 +27,7 @@ describe Role do
describe '.admins' do
let!(:admins) { FactoryBot.create_list(:admin_member, 3) }
it 'return the members that have the role of admin' do
expect(Role.admins).to match_array(admins)
end

View File

@@ -151,6 +151,7 @@ describe Seed do
context 'photos' do
let(:seed) { FactoryBot.create :seed }
before { seed.photos << FactoryBot.create(:photo) }
it 'is found in has_photos scope' do
Seed.has_photos.should include(seed)

View File

@@ -2,6 +2,7 @@ require 'rails_helper'
describe "crops/_planting_advice" do
let(:planting) { FactoryBot.create(:planting) }
subject { rendered }
shared_examples "render planting_advice" do

View File

@@ -4,6 +4,7 @@ describe 'home/_crops.html.haml', type: "view" do
let!(:crop) { FactoryBot.create(:crop, plantings: FactoryBot.create_list(:planting, 3)) }
let!(:photo) { FactoryBot.create(:photo, plantings: [crop.plantings.first]) }
let(:planting) { crop.plantings.first }
before(:each) { render }
it 'shows crops section' do
assert_select 'h2', text: 'Some of our crops'

View File

@@ -2,6 +2,7 @@ require 'rails_helper'
describe "members/index" do
let(:member) { FactoryBot.create(:london_member) }
before(:each) do
controller.stub(:current_user) { nil }
page = 1

View File

@@ -5,6 +5,7 @@ describe "plantings/index" do
let(:garden) { FactoryBot.create(:garden, owner: member) }
let(:tomato) { FactoryBot.create(:tomato) }
let(:maize) { FactoryBot.create(:maize) }
before(:each) do
controller.stub(:current_user) { nil }
page = 1

View File

@@ -28,6 +28,7 @@ describe "plantings/show" do
context 'planted from' do
let(:planting) { FactoryBot.create(:cutting_planting) }
it "shows planted_from" do
render
rendered.should have_content 'Planted from:'

View File

@@ -25,25 +25,30 @@ describe "posts/show" do
describe "should parse markdown into html" do
let(:post) { FactoryBot.create(:markdown_post, author: author) }
it { assert_select "strong", "strong" }
end
describe "shouldn't let html through in body" do
let(:post) { FactoryBot.create(:post, author: author, body: '<a href="http://evil.com">EVIL</a>') }
it { is_expected.to have_content('EVIL') }
it { is_expected.not_to have_link("http://evil.com") }
end
describe 'script tag in post body' do
let(:post) { FactoryBot.create(:post, author: author, body: "<script>alert('hakker!')</script>") }
it { is_expected.not_to have_selector('script') }
end
describe 'script tag in post title' do
let(:post) { FactoryBot.create(:post, author: author, subject: "<script>alert('hakker!')</script>") }
it { is_expected.not_to have_selector('script') }
end
describe 'has an anchor to the comments' do
let(:post) { FactoryBot.create(:post, author: author) }
it { is_expected.to have_selector('a[name=comments]') }
end
end
@@ -51,6 +56,7 @@ describe "posts/show" do
context "when there is one comment" do
let(:post) { FactoryBot.create(:html_post, author: author) }
let!(:comment) { FactoryBot.create(:comment, post: post) }
before(:each) do
@comments = post.comments
render
@@ -71,6 +77,7 @@ describe "posts/show" do
context "when there is more than one comment" do
let(:post) { FactoryBot.create(:html_post, author: author) }
before(:each) do
@comment1 = FactoryBot.create(:comment, post: post, body: "F1rst!!!",
created_at: Date.new(2010, 5, 17))
@@ -90,6 +97,7 @@ describe "posts/show" do
context "forum post" do
let(:post) { FactoryBot.create(:forum_post, author: author) }
before { render }
it "shows forum name" do
is_expected.to have_content "in #{post.forum.name}"
@@ -98,6 +106,7 @@ describe "posts/show" do
context "signed in" do
let(:post) { FactoryBot.create(:post, author: author) }
before(:each) do
sign_in author
controller.stub(:current_user) { author }