mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-27 03:02:43 -04:00
1
Gemfile
1
Gemfile
@@ -80,4 +80,5 @@ group :development, :test do
|
||||
gem 'webrat'
|
||||
gem 'watchr'
|
||||
gem 'spork', '~> 0.9.0.rc'
|
||||
gem 'factory_girl_rails', '~> 4.0'
|
||||
end
|
||||
|
||||
@@ -68,6 +68,11 @@ GEM
|
||||
eventmachine (1.0.0)
|
||||
execjs (1.4.0)
|
||||
multi_json (~> 1.0)
|
||||
factory_girl (4.1.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (4.1.0)
|
||||
factory_girl (~> 4.1.0)
|
||||
railties (>= 3.0.0)
|
||||
fastthread (1.0.7)
|
||||
friendly_id (4.0.9)
|
||||
fssm (0.2.9)
|
||||
@@ -204,6 +209,7 @@ DEPENDENCIES
|
||||
compass-rails (~> 1.0.3)
|
||||
devise
|
||||
diff-lcs
|
||||
factory_girl_rails (~> 4.0)
|
||||
friendly_id
|
||||
gravatar-ultimate
|
||||
haml
|
||||
|
||||
17
spec/factories/crop.rb
Normal file
17
spec/factories/crop.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
FactoryGirl.define do
|
||||
|
||||
factory :crop do
|
||||
|
||||
factory :tomato do
|
||||
system_name "Tomato"
|
||||
en_wikipedia_url "http://en.wikipedia.org/wiki/Tomato"
|
||||
end
|
||||
|
||||
factory :maize do
|
||||
system_name "Maize"
|
||||
en_wikipedia_url "http://en.wikipedia.org/wiki/Maize"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
@@ -4,9 +4,7 @@ describe Crop do
|
||||
context 'all fields present' do
|
||||
|
||||
before(:each) do
|
||||
@crop = Crop.new
|
||||
@crop.system_name = "Tomato"
|
||||
@crop.en_wikipedia_url = "http://en.wikipedia.org/wiki/Tomato"
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
end
|
||||
|
||||
it 'should save a basic crop' do
|
||||
@@ -36,10 +34,7 @@ describe Crop do
|
||||
|
||||
context 'random' do
|
||||
before(:each) do
|
||||
@crop = Crop.new
|
||||
@crop.system_name = "Tomato"
|
||||
@crop.en_wikipedia_url = "http://en.wikipedia.org/wiki/Tomato"
|
||||
@crop.save
|
||||
@crop = FactoryGirl.create(:tomato)
|
||||
end
|
||||
|
||||
it 'should find a random crop' do
|
||||
|
||||
27
spec/models/scientific_name_spec.rb
Normal file
27
spec/models/scientific_name_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ScientificName do
|
||||
context 'all fields present' do
|
||||
|
||||
before(:each) do
|
||||
@sn = FactoryGirl.create(:zea_mays)
|
||||
end
|
||||
|
||||
it 'should save a basic scientific name' do
|
||||
@sn.save.should be_true
|
||||
end
|
||||
|
||||
it 'should be fetchable from the database' do
|
||||
@sn.save
|
||||
@sn2 = ScientificName.find_by_scientific_name('Zea mays')
|
||||
@sn2.crop.system_name.should == "Maize"
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid data' do
|
||||
it 'should not save a scientific name without a name' do
|
||||
@sn = ScientificName.new
|
||||
expect { @sn.save }.to raise_error ActiveRecord::StatementInvalid
|
||||
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,16 +2,10 @@ require 'spec_helper'
|
||||
|
||||
describe "crops/index" do
|
||||
before(:each) do
|
||||
assign(:crops, [
|
||||
stub_model(Crop,
|
||||
:system_name => "Maize",
|
||||
:en_wikipedia_url => "http://en.wikipedia.org/wiki/Maize"
|
||||
),
|
||||
stub_model(Crop,
|
||||
:system_name => "Tomato",
|
||||
:en_wikipedia_url => "http://en.wikipedia.org/wiki/Tomato"
|
||||
)
|
||||
])
|
||||
assign(:crops, [
|
||||
FactoryGirl.create(:tomato),
|
||||
FactoryGirl.create(:maize)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of crops" do
|
||||
@@ -20,12 +14,12 @@ describe "crops/index" do
|
||||
assert_select "a", :text => "Maize"
|
||||
assert_select "a", :text => "Tomato"
|
||||
end
|
||||
|
||||
|
||||
it "counts the number of crops" do
|
||||
render
|
||||
rendered.should contain "Displaying 2 crops"
|
||||
end
|
||||
|
||||
|
||||
context "logged out" do
|
||||
it "doesn't show the new crop link if logged out" do
|
||||
render
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,10 +2,9 @@ require 'spec_helper'
|
||||
|
||||
describe "scientific_names/edit" do
|
||||
before(:each) do
|
||||
@scientific_name = assign(:scientific_name, stub_model(ScientificName,
|
||||
:scientific_name => "MyString",
|
||||
:crop_id => 1
|
||||
))
|
||||
@scientific_name = assign(:scientific_name,
|
||||
FactoryGirl.create(:zea_mays)
|
||||
)
|
||||
end
|
||||
|
||||
context "logged out" do
|
||||
@@ -17,8 +16,7 @@ describe "scientific_names/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
|
||||
|
||||
@@ -3,21 +3,15 @@ require 'spec_helper'
|
||||
describe "scientific_names/index" do
|
||||
before(:each) do
|
||||
assign(:scientific_names, [
|
||||
stub_model(ScientificName,
|
||||
:scientific_name => "Scientific Name",
|
||||
:crop_id => 1
|
||||
),
|
||||
stub_model(ScientificName,
|
||||
:scientific_name => "Scientific Name",
|
||||
:crop_id => 1
|
||||
)
|
||||
FactoryGirl.create(:zea_mays),
|
||||
FactoryGirl.create(:solanum_lycopersicum)
|
||||
])
|
||||
end
|
||||
|
||||
it "renders a list of scientific_names" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
assert_select "tr>td", :text => "Scientific Name".to_s, :count => 2
|
||||
assert_select "tr>td", :text => 1.to_s, :count => 2
|
||||
assert_select "tr>td", :text => "Zea mays".to_s
|
||||
assert_select "tr>td", :text => "Solanum lycopersicum".to_s
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,10 +2,7 @@ require 'spec_helper'
|
||||
|
||||
describe "scientific_names/new" do
|
||||
before(:each) do
|
||||
assign(:scientific_name, stub_model(ScientificName,
|
||||
:scientific_name => "MyString",
|
||||
:crop_id => 1
|
||||
).as_new_record)
|
||||
assign(:scientific_name, FactoryGirl.create(:zea_mays))
|
||||
end
|
||||
|
||||
context "logged out" do
|
||||
@@ -17,8 +14,7 @@ describe "scientific_names/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,16 +2,15 @@ require 'spec_helper'
|
||||
|
||||
describe "scientific_names/show" do
|
||||
before(:each) do
|
||||
@scientific_name = assign(:scientific_name, stub_model(ScientificName,
|
||||
:scientific_name => "Scientific Name",
|
||||
:crop_id => 1
|
||||
))
|
||||
@scientific_name = assign(:scientific_name,
|
||||
FactoryGirl.create(:zea_mays)
|
||||
)
|
||||
end
|
||||
|
||||
it "renders attributes in <p>" do
|
||||
render
|
||||
# Run the generator again with the --webrat flag if you want to use webrat matchers
|
||||
rendered.should match(/Scientific Name/)
|
||||
rendered.should match(/1/)
|
||||
rendered.should match(/Zea mays/)
|
||||
rendered.should match(@scientific_name.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user