From 4e3c47a82f84ee1d410bf866ea62075bf24655e3 Mon Sep 17 00:00:00 2001 From: Skud Date: Wed, 7 Nov 2012 13:19:59 +1100 Subject: [PATCH] Showing scientific names on the crop page --- Gemfile.lock | 16 ++++++++-------- app/views/crops/show.html.haml | 7 +++++++ db/seeds.rb | 10 ++++++++++ spec/views/crops/show.html.haml_spec.rb | 20 ++++++++++++++++++-- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 04049ceb5..5f89daaf5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GEM bcrypt-ruby (3.0.1) builder (3.0.4) cape (1.5.0) - capistrano (2.13.4) + capistrano (2.13.5) highline net-scp (>= 1.0.0) net-sftp (>= 2.0.0) @@ -54,7 +54,7 @@ GEM sass (~> 3.1) compass-rails (1.0.3) compass (>= 0.12.2, < 0.14) - daemon_controller (1.0.0) + daemon_controller (1.1.0) devise (2.1.2) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) @@ -65,7 +65,7 @@ GEM execjs (1.4.0) multi_json (~> 1.0) fastthread (1.0.7) - friendly_id (4.0.8) + friendly_id (4.0.9) fssm (0.2.9) haml (3.1.7) haml-rails (0.3.5) @@ -90,7 +90,7 @@ GEM modular-scale (1.0.2) compass (>= 0.11.5) sassy-math (>= 1.2) - multi_json (1.3.6) + multi_json (1.3.7) net-scp (1.0.4) net-ssh (>= 1.99.1) net-sftp (2.0.5) @@ -100,7 +100,7 @@ GEM net-ssh (>= 1.99.1) nokogiri (1.5.5) orm_adapter (0.4.0) - passenger (3.0.17) + passenger (3.0.18) daemon_controller (>= 1.0.0) fastthread (>= 1.0.1) rack @@ -147,7 +147,7 @@ GEM rspec (~> 2.11.0) rvm-capistrano (1.2.7) capistrano (>= 2.0.0) - sass (3.2.1) + sass (3.2.2) sass-rails (3.2.5) railties (~> 3.2.0) sass (>= 3.1.10) @@ -164,10 +164,10 @@ GEM libv8 (~> 3.3.10) thor (0.16.0) tilt (1.3.3) - treetop (1.4.11) + treetop (1.4.12) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.33) + tzinfo (0.3.35) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index fcd7bfcd6..93db4ef34 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -1,5 +1,12 @@ - content_for :title, @crop.system_name +%p + %b Scientific names: + +%ul + - @crop.scientific_names.each do |sn| + %li= sn.scientific_name + %p %b More information: = link_to @crop.en_wikipedia_url, @crop.en_wikipedia_url diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857..cf9979d2c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,13 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +# import crops from CSV + +require 'csv' + +CSV.foreach(Rails.root.join('db', 'seeds', 'crops.csv')) do |row| + system_name,scientific_name,en_wikipedia_url = row + @crop = Crop.create(:system_name => system_name, :en_wikipedia_url => en_wikipedia_url) + @crop.scientific_names.create(:scientific_name => scientific_name) +end diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 60a04f9d9..65a313948 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -3,9 +3,25 @@ require 'spec_helper' describe "crops/show" do before(:each) do @crop = assign(:crop, stub_model(Crop, - :system_name => "System Name", - :en_wikipedia_url => "En Wikipedia Url" + :id => 1, + :system_name => "Corn", + :en_wikipedia_url => "http://en.wikipedia.org/Maize" )) + @crop.scientific_names.create( + :scientific_name => "Zea mays", + :crop_id => 1 + ) + end + + it "shows the wikipedia URL" do + render + rendered.should contain "en.wikipedia.org" + end + + it "shows the scientific name" do + render + rendered.should contain "Scientific names" + rendered.should contain "Zea mays" end context "logged out" do