Skip to content

Commit

Permalink
Merge pull request #969 from openfarmcc/dep_upgrades
Browse files Browse the repository at this point in the history
Test Updates
  • Loading branch information
RickCarlino committed May 17, 2018
2 parents 3885057 + b960f86 commit 221ea83
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 106 deletions.
2 changes: 2 additions & 0 deletions spec/controllers/api/api_crops_controller_spec.rb
Expand Up @@ -6,6 +6,8 @@
let(:user) { FactoryGirl.create(:user) }

before do
Crop.destroy_all
FactoryGirl.create(:crop, name: 'other bean')
@beans = FactoryGirl.create(:crop, name: 'mung bean')
FactoryGirl.create_list(:crop, 2)
Crop.searchkick_index.refresh
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/api/api_tags_controller_spec.rb
Expand Up @@ -5,6 +5,7 @@
let(:user) { FactoryGirl.create(:user) }

before do
Crop.destroy_all
FactoryGirl.create(:crop, name: 'mung bean', tags: 'tagOne')
FactoryGirl.create(:crop, tags: 'tagTwo')
Crop.searchkick_index.refresh
Expand All @@ -19,7 +20,7 @@
end

it 'returns the tag matching the query' do
get 'index', format: :json, query: 'on'
get 'index', format: :json, query: 'one'
expect(response.status).to eq(200)
expect(json.length).to eq(1)
expect(json[0]).to eq('tagOne')
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Expand Up @@ -39,11 +39,11 @@
public_user = FactoryGirl.create(:user)
sign_in user
get :index
expect(assigns(:users)).to match_array([public_user, user])
expect(assigns(:users).to_a.map(&:is_private).uniq).to match_array([false])
end

it 'should show all users on index if the current user is admin' do
skip 'this test does not pass on CI - RickCarlino'
User.destroy_all
user = FactoryGirl.create(:user, admin: true)
private_user = FactoryGirl.create(:user, is_private: true)
public_user = FactoryGirl.create(:user)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/announcement_spec.rb
Expand Up @@ -19,7 +19,7 @@
end

it 'shows announcements that have been updated since the hide time' do
skip 'fails on CI - RickCarlino'
Announcement.destroy_all
announcement = Announcement.create(message: 'Test Announcement',
starts_at: Time.zone.now.to_date.prev_day,
ends_at: Time.zone.now.to_date.next_day)
Expand Down
115 changes: 57 additions & 58 deletions spec/features/crop_searches_spec.rb
@@ -1,14 +1,14 @@
require 'spec_helper'

describe 'Crop search', type: :controller do
# def asset_url(relative_path)
# "#{host_with_port}#{Rails.application.config.assets.prefix}/"+
# "#{relative_path}"
# end
def asset_url(relative_path)
"#{host_with_port}#{Rails.application.config.assets.prefix}/"+
"#{relative_path}"
end

# def host_with_port
# "#{current_host}:#{Capybara.current_session.server.port}"
# end
def host_with_port
"#{current_host}:#{Capybara.current_session.server.port}"
end

let!(:crop) { FactoryGirl.create(:crop, :radish) }

Expand All @@ -24,59 +24,58 @@
# .to_not have_content("Sorry, we don't have any crops matching")
# end

it 'handles empty searches' # , js: true do
# skip 'this test does not pass on CI - RickCarlino'
# visit root_path
# fill_in 'q', with: ''
# FactoryGirl.create_list(:crop, 10)
# Crop.searchkick_index.refresh
# click_button 'Search'
# expect(page).to have_content(Crop.last.name)
# title = Crop.first.name
# description = Crop.first.description
# image = Crop.first.main_image_path
# expect(page)
# .to have_css "meta[property='og:title'][content='#{title}']",
# visible: false
# expect(page)
# .to have_css "meta[property='og:description']"+
# "[content='#{description}']", visible: false
# expect(page).to have_css "meta[property='og:image']"+
# "[content='#{host_with_port}#{image}']",
# visible: false
# end
it 'handles empty searches', js: true do
Crop.destroy_all
visit root_path
fill_in 'q', with: ''
FactoryGirl.create_list(:crop, 10)
Crop.searchkick_index.refresh
click_button 'Search'
expect(page).to have_content(Crop.last.name)
# Don't use crops with apostraphes in the name- creates weird errors.
crop = Crop.all.to_a.detect { |x| !x.name.include?("'") }
title = crop.name
description = crop.description
image = crop.main_image_path
selector1 = "meta[property='og:title'][content='#{title}']"
expect(page).to have_css(selector1, visible: false)
selector2 = "meta[property='og:description'][content='#{description}']"
expect(page).to have_css(selector2, visible: false)
selector3 = "meta[property='og:image']"+
"[content='#{host_with_port}#{image}']"
expect(page).to have_css(selector3, visible: false)
end

it 'handles empty search results' # , js: true do
# skip 'this test does not pass on CI - RickCarlino'
# visit root_path
# fill_in 'q', with: 'pokemon'
# FactoryGirl.create_list(:crop, 10)
# Crop.searchkick_index.refresh
# click_button 'Search'
# expect(page).to have_content("Sorry, we don't have any crops matching")
# description = I18n.t('application.site_description')
# title = I18n.t('crop_searches.show.title')
# image = \
# 'openfarm-learn-to-grow-anything-with-community-created-guides.jpg'
# expect(page)
# .to have_css "meta[property='og:description']"+
# "[content='#{description}']", visible: false
# expect(page).to have_css "meta[property='og:title'][content='#{title}']",
# visible: false
# expect(page).to have_css "meta[property='og:image']"+
# "[content='#{asset_url(image)}']", visible: false
# end
it 'handles empty search results', js: true do
Crop.destroy_all
FactoryGirl.create_list(:crop, 10)
Crop.searchkick_index.refresh
visit root_path
fill_in 'q', with: 'pokemon'
click_button 'Search'
expect(page).to have_content("Sorry, we don't have any crops matching")
description = I18n.t('application.site_description')
title = I18n.t('crop_searches.show.title')
image = 'openfarm-learn-to-grow-anything-with-community-created-guides.jpg'
selector1 = "meta[property='og:description'][content='#{description}']"
expect(page).to have_css(selector1, visible: false)
selector2 = "meta[property='og:title'][content='#{title}']"
expect(page).to have_css(selector2, visible: false)
selector3 = "meta[property='og:image'][content='#{asset_url(image)}']"
expect(page).to have_css(selector3, visible: false)
end

it 'handles plurals' # , js: true do
# visit root_path
# fill_in 'q', with: crop.name
# FactoryGirl.create_list(:crop, 10)
# Crop.searchkick_index.refresh
# click_button 'Search'
# expect(page).to have_content(crop.name)
# expect(page)
# .to_not have_content("Sorry, we don't have any crops matching")
# end
it 'handles plurals', js: true do
Crop.destroy_all
FactoryGirl.create_list(:crop, 10)
q = FactoryGirl.create(:crop, :radish).name
Crop.searchkick_index.refresh
visit root_path
fill_in 'q', with: q
click_button 'Search'
expect(page).to have_content(crop.name)
expect(page).to_not have_content("Sorry, we don't have any crops matching")
end

it 'handles misspellings' # , js: true do
# visit root_path
Expand Down
13 changes: 7 additions & 6 deletions spec/features/user_sessions_spec.rb
Expand Up @@ -6,7 +6,7 @@
let(:user) { FactoryGirl.create(:user) }

it 'registers for an account should not be confirmed' do
skip 'this test does not pass on CI - RickCarlino'
User.destroy_all
visit root_path
click_link 'register'
fill_in :user_display_name, with: 'Rick'
Expand Down Expand Up @@ -34,7 +34,7 @@
end

it 'should redirect the user to their finish page after sign up' do
skip 'this test does not pass on CI - RickCarlino'
User.destroy_all
visit new_user_registration_path
fill_in :user_display_name, with: 'Rick'
fill_in :user_password, with: 'password123'
Expand All @@ -43,17 +43,17 @@
expect(page).to have_content('Thanks for joining!')
end

it 'should redirect the user to the page they were viewing after sign up' do
skip 'this test does not pass on CI - RickCarlino'
it 'should redirect the user to the page they' \
'were viewing after sign up', js: true do
User.destroy_all
visit new_guide_path
see ('You need to sign in or sign up before continuing.')
page.first(:link, 'Become a Member').click
fill_in :user_display_name, with: 'Rick'
fill_in :user_password, with: 'password123'
fill_in :user_email, with: 'm@il.com'
click_button 'Join OpenFarm'
string_ref = 'guides.new.new_guide_steps.create_a_growing_guide'
expect(page).to have_content(I18n::t(string_ref))
expect(page).to have_content('Create a Growing Guide')
end

it 'should create a new garden for a newly registered user' do
Expand Down Expand Up @@ -151,6 +151,7 @@ def extract_url_from_email(email)
end

def sign_up_procedure
User.destroy_all
visit root_path
click_link 'register'
fill_in :user_display_name, with: 'Rick'
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/reindex_guides_job_spec.rb
Expand Up @@ -2,7 +2,7 @@

describe ReindexGuidesJob do
it 'reindexes guides' do
skip 'this test does not pass on CI - RickCarlino'
Guide.destroy_all
FactoryGirl.create(:guide)
expect_any_instance_of(Guide).to receive(:reindex_async)
ReindexGuidesJob.new.perform
Expand Down
8 changes: 4 additions & 4 deletions spec/models/crop_spec.rb
Expand Up @@ -16,20 +16,20 @@
it 'searches by name' do
skip 'this test does not pass on CI - RickCarlino'
Crop.searchkick_index.refresh
result = Crop.search('Common Horseradish').first
expect(result).to eq(crop)
results = Crop.search('Common Horseradish').to_a
expect(results).to include(crop)
end

it 'searches by binomial name' do
skip 'this test does not pass on CI - RickCarlino'
Crop.searchkick_index.refresh
expect(Crop.search('Armoracia rusticana').first).to eq(crop)
expect(Crop.search('Armoracia rusticana').to_a).to include(crop)
end

it 'searches by description' do
skip 'this test does not pass on CI - RickCarlino'
Crop.searchkick_index.refresh
expect(Crop.search('Brassicaceae family').first).to eq(crop)
expect(Crop.search('Brassicaceae family').to_a).to include(crop)
end

it 'displays the main_image_path' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/garden_crop_spec.rb
Expand Up @@ -23,7 +23,7 @@
end

it 'reindexes guides' do
skip 'this test does not pass on CI - RickCarlino'
Guide.destroy_all
FactoryGirl.create(:guide)

expect_any_instance_of(Guide).to receive(:reindex_async)
Expand Down
1 change: 1 addition & 0 deletions spec/models/guide_search_spec.rb
Expand Up @@ -39,6 +39,7 @@
end

it 'knows if it is empty' do
Guide.reindex
subject.search('this will not return anything')

expect(subject).to be_empty
Expand Down
1 change: 1 addition & 0 deletions spec/models/guide_spec.rb
Expand Up @@ -80,6 +80,7 @@
end

it 'sets the popularity score' do
Guide.destroy_all
FactoryGirl.create(:guide)
FactoryGirl.create(:guide)
guide = FactoryGirl.create(:guide)
Expand Down
1 change: 1 addition & 0 deletions spec/models/token_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'openfarm_errors'

describe Token do
let(:token) { FactoryGirl.create(:token) }
Expand Down
69 changes: 39 additions & 30 deletions spec/policies/garden_policy_spec.rb
Expand Up @@ -30,47 +30,56 @@

context 'for a user' do
it 'should only return gardens in scope that are public' do
skip 'this test does not pass on CI - RickCarlino'
Garden.destroy_all
other_user = FactoryGirl.create :user
FactoryGirl.create :garden,
is_private: true,
name: 'nono',
user: other_user
FactoryGirl.create :garden,
is_private: false,
name: 'yes!',
user: other_user
not_mine = FactoryGirl.create :garden,
is_private: true,
name: 'not_mine',
user: other_user
shared = FactoryGirl.create :garden,
is_private: false,
name: 'yes!',
user: other_user
@p = GardenPolicy::Scope.new(current_user, Garden).resolve
expect(@p.length).to eq(2)
expect(@p).not_to include(not_mine)
expect(@p).to include(shared)
end

it 'should only return public gardens unless they are current_user' do
skip 'this test does not pass on CI - RickCarlino'
Garden.destroy_all
other_user = FactoryGirl.create :user
FactoryGirl.create :garden,
is_private: true,
name: 'nono',
user: current_user
FactoryGirl.create :garden,
is_private: false,
name: 'yes!',
user: other_user
mine = FactoryGirl.create :garden,
is_private: true,
name: 'mine',
user: current_user
publicly_shared = FactoryGirl.create :garden,
is_private: false,
name: 'not mine but OK (public)',
user: other_user
not_mine = FactoryGirl.create :garden,
is_private: true,
name: 'not mine',
user: other_user
@p = GardenPolicy::Scope.new(current_user, Garden).resolve
expect(@p.length).to eq(3)
expect(@p).to include(mine)
expect(@p).to include(publicly_shared)
expect(@p).not_to include(not_mine)
end

it 'should return all gardens in scope when user is admin' do
skip 'this test does not pass on CI - RickCarlino'
FactoryGirl.create :garden,
is_private: true,
name: 'nono',
user: current_user
FactoryGirl.create :garden,
is_private: false,
name: 'yes!',
user: current_user
Garden.destroy_all
a = FactoryGirl.create :garden,
is_private: true,
name: 'nono',
user: current_user
b = FactoryGirl.create :garden,
is_private: false,
name: 'yes!',
user: current_user
@p = GardenPolicy::Scope.new(admin, Garden).resolve
expect(@p.length).to eq(4)
expect(@p).to include(a)
expect(@p).to include(b)
expect(@p.length).to eq(Garden.count)
end
end
end

0 comments on commit 221ea83

Please sign in to comment.