mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 11:14:31 -04:00
factory-girl-ified the views/crops tests
This commit is contained in:
@@ -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
|
||||
|
||||
12
spec/factories/scientific_name.rb
Normal file
12
spec/factories/scientific_name.rb
Normal file
@@ -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
|
||||
15
spec/factories/user.rb
Normal file
15
spec/factories/user.rb
Normal file
@@ -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
|
||||
@@ -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]"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user