diff --git a/spec/factories/crop.rb b/spec/factories/crop.rb index 88eb6af2d..900141e1a 100644 --- a/spec/factories/crop.rb +++ b/spec/factories/crop.rb @@ -2,12 +2,12 @@ FactoryGirl.define do factory :crop do - factory :tomato do + factory :tomato do |t| system_name "Tomato" en_wikipedia_url "http://en.wikipedia.org/wiki/Tomato" end - factory :maize do + factory :maize do |m| system_name "Maize" en_wikipedia_url "http://en.wikipedia.org/wiki/Maize" end diff --git a/spec/factories/scientific_name.rb b/spec/factories/scientific_name.rb new file mode 100644 index 000000000..7bb3e4cd9 --- /dev/null +++ b/spec/factories/scientific_name.rb @@ -0,0 +1,12 @@ +FactoryGirl.define do + factory :scientific_name do + factory :zea_mays do + association :crop, factory: :maize + scientific_name "Zea mays" + end + factory :solanum_lycopersicum do + association :crop, factory: :tomato + scientific_name "Solanum lycopersicum" + end + end +end diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 000000000..d5d3dc5cb --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + + factory :user do + username "user1" + password "password1" + email "user1@example.com" + tos_agreement true + + factory :confirmed_user do + confirmed_at Time.now() + end + + end + +end diff --git a/spec/views/crops/edit.html.haml_spec.rb b/spec/views/crops/edit.html.haml_spec.rb index 51f442e4e..c400c83a0 100644 --- a/spec/views/crops/edit.html.haml_spec.rb +++ b/spec/views/crops/edit.html.haml_spec.rb @@ -2,10 +2,7 @@ require 'spec_helper' describe "crops/edit" do before(:each) do - @crop = assign(:crop, stub_model(Crop, - :system_name => "MyString", - :en_wikipedia_url => "MyString" - )) + @crop = assign(:crop, FactoryGirl.create(:maize)) end context "logged out" do @@ -17,14 +14,12 @@ describe "crops/edit" do context "logged in" do before(:each) do - @user = User.create(:email => "growstuff@example.com", :password => "irrelevant") - @user.confirm! + @user = FactoryGirl.create(:confirmed_user) sign_in @user render end it "renders the edit crop form" do - render # Run the generator again with the --webrat flag if you want to use webrat matchers assert_select "form", :action => crops_path(@crop), :method => "post" do assert_select "input#crop_system_name", :name => "crop[system_name]" diff --git a/spec/views/crops/new.html.haml_spec.rb b/spec/views/crops/new.html.haml_spec.rb index 0565ef03b..d92ef4fb0 100644 --- a/spec/views/crops/new.html.haml_spec.rb +++ b/spec/views/crops/new.html.haml_spec.rb @@ -2,10 +2,7 @@ require 'spec_helper' describe "crops/new" do before(:each) do - assign(:crop, stub_model(Crop, - :system_name => "MyString", - :en_wikipedia_url => "MyString" - ).as_new_record) + assign(:crop, FactoryGirl.create(:maize)) end context "logged out" do @@ -18,8 +15,7 @@ describe "crops/new" do context "logged in" do before(:each) do - @user = User.create(:email => "growstuff@example.com", :password => "irrelevant") - @user.confirm! + @user = FactoryGirl.create(:confirmed_user) sign_in @user render end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 384b87fdb..2e165c8ab 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -2,15 +2,9 @@ require 'spec_helper' describe "crops/show" do before(:each) do - @crop = assign(:crop, stub_model(Crop, - :id => 1, - :system_name => "Corn", - :en_wikipedia_url => "http://en.wikipedia.org/Maize" + @crop = assign(:crop, FactoryGirl.create(:maize, + :scientific_names => [ FactoryGirl.create(:zea_mays) ] )) - @crop.scientific_names.create( - :scientific_name => "Zea mays", - :crop_id => 1 - ) end it "shows the wikipedia URL" do @@ -31,7 +25,7 @@ describe "crops/show" do it "links to the right crop in the planting link" do render - assert_select("a[href=#{new_planting_path}?crop_id=1]") + assert_select("a[href=#{new_planting_path}?crop_id=#{@crop.id}]") end context "logged out" do