factory-girl-ified the views/crops tests

This commit is contained in:
Skud
2013-01-11 11:39:50 +11:00
parent fe24802790
commit 46fd6953ac
6 changed files with 36 additions and 24 deletions

View File

@@ -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

View 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
View 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

View File

@@ -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]"

View File

@@ -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

View File

@@ -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