Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Refactor spec
Browse files Browse the repository at this point in the history
Refactor spec by changing before(:each) into let
  • Loading branch information
Cjay Billones committed Jul 6, 2015
1 parent 45c0adb commit e94cbce
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 48 deletions.
11 changes: 4 additions & 7 deletions spec/features/admin/account_types_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

feature "account types" do
context "admin user" do
before(:each) do
@member = FactoryGirl.create(:admin_member)
visit root_path
click_link 'Sign in'
fill_in 'Login', :with => @member.login_name
fill_in 'Password', :with => @member.password
click_button 'Sign in'
let(:member) { FactoryGirl.create(:admin_member) }

background do
login_as member
end

scenario "navigating to account type admin" do
Expand Down
11 changes: 4 additions & 7 deletions spec/features/admin/forums_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

feature "forums" do
context "admin user" do
before(:each) do
@member = FactoryGirl.create(:admin_member)
visit root_path
click_link 'Sign in'
fill_in 'Login', :with => @member.login_name
fill_in 'Password', :with => @member.password
click_button 'Sign in'
let(:member) { FactoryGirl.create(:admin_member) }

background do
login_as member
end

scenario "navigating to forum admin" do
Expand Down
3 changes: 2 additions & 1 deletion spec/features/admin/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
feature "products" do
context "admin user" do
let(:member) { FactoryGirl.create(:admin_member) }

background do
login_as(member)
login_as member
end

scenario "navigating to product admin" do
Expand Down
22 changes: 6 additions & 16 deletions spec/features/cms_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
require 'spec_helper'
require 'rails_helper'

feature "cms admin" do
before(:each) do
@member = FactoryGirl.create(:member)
@admin_member = FactoryGirl.create(:admin_member)
end

let(:member) { FactoryGirl.create(:member) }
let(:admin_member) { FactoryGirl.create(:admin_member) }

scenario "can't view CMS admin if not signed in" do
visit comfy_admin_cms_path
Expand All @@ -14,23 +13,14 @@

scenario "can't view CMS admin if not an admin member" do
# sign in as an ordinary member
visit root_path
click_link 'navbar-signin'
fill_in 'Login', :with => @member.email
fill_in 'Password', :with => @member.password
click_button 'Sign in'
login_as member
visit comfy_admin_cms_path
current_path.should == root_path
page.should have_content("Please sign in as an admin user")
end

scenario "admin members can view CMS admin area" do
visit root_path
# now we sign in as an admin member
click_link 'navbar-signin'
fill_in 'Login', :with => @admin_member.email
fill_in 'Password', :with => @admin_member.password
click_button 'Sign in'
login_as admin_member
visit comfy_admin_cms_path
current_path.should match /#{comfy_admin_cms_path}/ # match any CMS admin page
end
Expand Down
4 changes: 2 additions & 2 deletions spec/features/crops/alternate_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) }
let(:member){crop_wranglers.first}

before :each do
login_as(member)
background do
login_as member
end

scenario "Crop wranglers can edit alternate names" do
Expand Down
8 changes: 6 additions & 2 deletions spec/features/crops/request_new_crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
let(:member) { FactoryGirl.create(:member) }
let!(:wrangler) { FactoryGirl.create(:crop_wrangling_member) }

before { login_as member }
background do
login_as member
end

scenario "Submit request" do
visit new_crop_path
Expand All @@ -25,7 +27,9 @@
let!(:crop) { FactoryGirl.create(:crop_request) }
let!(:already_approved) { FactoryGirl.create(:crop) }

before { login_as wrangler }
background do
login_as wrangler
end

scenario "Approve a request" do
visit edit_crop_path(crop)
Expand Down
2 changes: 1 addition & 1 deletion spec/features/harvests/harvesting_a_crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let!(:maize) { FactoryGirl.create(:maize) }

background do
login_as(member)
login_as member
visit new_harvest_path
sync_elasticsearch([maize])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/photos/show_photo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let (:member) { FactoryGirl.create(:member) }

background do
login_as(member)
login_as member
end

context "linked to planting" do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/plantings/planting_a_crop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let!(:planting) { FactoryGirl.create(:planting, garden: garden, planted_at: Date.parse("2013-3-10")) }

background do
login_as(member)
login_as member
visit new_planting_path
sync_elasticsearch([maize])
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/scientific_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let!(:crop_wranglers) { FactoryGirl.create_list(:crop_wrangling_member, 3) }
let(:member){crop_wranglers.first}

before :each do
background do
login_as(member)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/features/seeds/adding_seeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let!(:maize) { FactoryGirl.create(:maize) }

background do
login_as(member)
login_as member
visit new_seed_path
sync_elasticsearch([maize])
end
Expand Down
14 changes: 6 additions & 8 deletions spec/features/seeds/misc_seeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

feature "seeds" do
context "signed in user" do
before(:each) do
@crop = FactoryGirl.create(:crop)
@member = FactoryGirl.create(:member)
visit root_path
click_link 'Sign in'
fill_in 'Login', :with => @member.login_name
fill_in 'Password', :with => @member.password
click_button 'Sign in'

let(:member) { @member = FactoryGirl.create(:member) }
let(:crop) { FactoryGirl.create(:crop) }

background do
login_as member
end

scenario "button on index to edit seed" do
Expand Down

0 comments on commit e94cbce

Please sign in to comment.