From 3a96cd96dfe771671316013152e5baf260857789 Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 22 Jul 2013 15:47:25 +1000 Subject: [PATCH] removed tradable boolean field we're now relying just on the "tradable_to" field, which is clearer. --- Gemfile.lock | 73 +++++++++---------- app/models/seed.rb | 14 +++- app/views/seeds/_form.html.haml | 11 ++- app/views/seeds/index.html.haml | 3 +- app/views/seeds/show.html.haml | 12 +-- ...130722050836_remove_tradable_from_seeds.rb | 9 +++ db/schema.rb | 3 +- spec/factories/seeds.rb | 5 +- spec/models/seed_spec.rb | 23 +++++- spec/views/seeds/edit.html.haml_spec.rb | 1 - spec/views/seeds/index.html.haml_spec.rb | 2 +- spec/views/seeds/new.html.haml_spec.rb | 1 - spec/views/seeds/show.html.haml_spec.rb | 4 +- 13 files changed, 96 insertions(+), 65 deletions(-) create mode 100644 db/migrate/20130722050836_remove_tradable_from_seeds.rb diff --git a/Gemfile.lock b/Gemfile.lock index 1f460549e..e82224106 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,20 +52,20 @@ GEM i18n (= 0.6.1) multi_json (~> 1.0) arel (3.0.2) - bcrypt-ruby (3.0.1) + bcrypt-ruby (3.1.1) bluecloth (2.2.0) - bootstrap-datepicker-rails (1.0.0) + bootstrap-datepicker-rails (1.1.1.3) railties (>= 3.0) builder (3.0.4) - cancan (1.6.9) - chunky_png (1.2.7) + cancan (1.6.10) + chunky_png (1.2.8) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) coffee-script (2.2.0) coffee-script-source execjs - coffee-script-source (1.6.2) + coffee-script-source (1.6.3) colorize (0.5.8) columnize (0.3.6) commonjs (0.2.6) @@ -82,17 +82,17 @@ GEM simplecov (>= 0.7) thor dalli (2.6.4) - debugger (1.6.0) + debugger (1.6.1) columnize (>= 0.3.1) debugger-linecache (~> 1.2.0) - debugger-ruby_core_source (~> 1.2.1) + debugger-ruby_core_source (~> 1.2.3) debugger-linecache (1.2.0) - debugger-ruby_core_source (1.2.2) - devise (2.2.3) + debugger-ruby_core_source (1.2.3) + devise (3.0.0) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) - railties (~> 3.1) - warden (~> 1.2.1) + railties (>= 3.2.6, < 5) + warden (~> 1.2.3) diff-lcs (1.1.3) erubis (2.7.0) execjs (1.4.0) @@ -105,55 +105,54 @@ GEM flickraw (0.9.6) friendly_id (4.0.9) fssm (0.2.10) - geocoder (1.1.6) + geocoder (1.1.8) gravatar-ultimate (1.0.3) - haml (4.0.0) + haml (4.0.3) tilt haml-rails (0.4) actionpack (>= 3.1, < 4.1) activesupport (>= 3.1, < 4.1) haml (>= 3.1, < 4.1) railties (>= 3.1, < 4.1) - hashie (1.2.0) - hike (1.2.1) + hashie (2.0.5) + hike (1.2.3) i18n (0.6.1) journey (1.0.4) - jquery-rails (2.2.1) + jquery-rails (3.0.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.7.7) kgio (2.8.0) - less (2.3.1) + less (2.3.2) commonjs (~> 0.2.6) - less-rails (2.3.2) + less-rails (2.3.3) actionpack (>= 3.1) less (~> 2.3.1) libv8 (3.3.10.4) - mail (2.5.3) - i18n (>= 0.4.0) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) memcachier (0.0.2) - mime-types (1.21) - mini_portile (0.5.0) - multi_json (1.7.1) - newrelic_rpm (3.5.8.72) + mime-types (1.23) + mini_portile (0.5.1) + multi_json (1.7.7) + newrelic_rpm (3.6.5.130) nokogiri (1.6.0) mini_portile (~> 0.5.0) oauth (0.4.7) - omniauth (1.1.3) - hashie (~> 1.2) + omniauth (1.1.4) + hashie (>= 1.2, < 3) rack omniauth-flickr (0.0.11) omniauth-oauth (~> 1.0) omniauth-oauth (1.0.1) oauth omniauth (~> 1.0) - omniauth-twitter (0.0.16) + omniauth-twitter (1.0.0) multi_json (~> 1.3) omniauth-oauth (~> 1.0) orm_adapter (0.4.0) - pg (0.14.1) + pg (0.15.1) polyglot (0.3.3) rack (1.4.5) rack-cache (1.2) @@ -177,8 +176,8 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - raindrops (0.10.0) - rake (10.0.3) + raindrops (0.11.0) + rake (10.1.0) rdoc (3.12.2) json (~> 1.4) rest-client (1.6.7) @@ -194,7 +193,7 @@ GEM rspec-core (~> 2.12.0) rspec-expectations (~> 2.12.0) rspec-mocks (~> 2.12.0) - sass (3.2.7) + sass (3.2.9) sass-rails (3.2.6) railties (~> 3.2.0) sass (>= 3.1.10) @@ -211,20 +210,20 @@ GEM sqlite3 (1.3.7) therubyracer (0.10.2) libv8 (~> 3.3.10) - thor (0.17.0) - tilt (1.3.6) - treetop (1.4.12) + thor (0.18.1) + tilt (1.4.1) + treetop (1.4.14) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) - uglifier (1.3.0) + uglifier (2.1.2) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) - unicorn (4.6.2) + unicorn (4.6.3) kgio (~> 2.6) rack raindrops (~> 0.7) - warden (1.2.1) + warden (1.2.3) rack (>= 1.0) webrat (0.7.3) nokogiri (>= 1.2.0) diff --git a/app/models/seed.rb b/app/models/seed.rb index bc9038359..7d2ecd371 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -1,12 +1,20 @@ class Seed < ActiveRecord::Base attr_accessible :owner_id, :crop_id, :description, :quantity, :plant_before, - :tradable, :tradable_to + :tradable_to belongs_to :crop belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id' - TRADABLE_TO_VALUES = %w(locally nationally internationally) + TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally) validates :tradable_to, :inclusion => { :in => TRADABLE_TO_VALUES, - :message => "You may only trade seed locally, nationally, or internationally" }, + :message => "You may only trade seed nowhere, locally, nationally, or internationally" }, :allow_nil => true, :allow_blank => true + + def tradable? + if self.tradable_to == 'nowhere' + return false + else + return true + end + end end diff --git a/app/views/seeds/_form.html.haml b/app/views/seeds/_form.html.haml index 001a40668..819c5c0b6 100644 --- a/app/views/seeds/_form.html.haml +++ b/app/views/seeds/_form.html.haml @@ -19,13 +19,10 @@ .control-group = f.label 'Plant before:', :class => 'control-label' .controls= f.text_field :plant_before, :value => @seed.plant_before ? @seed.plant_before.to_s(:ymd) : '', :class => 'add-datepicker' - .control-group - = f.label 'Willing to trade:', :class => 'control-label' - .controls= f.check_box :tradable .control-group = f.label 'Will trade:', :class => 'control-label' .controls - = f.select(:tradable_to, Seed::TRADABLE_TO_VALUES, {:include_blank => true}) + = f.select(:tradable_to, options_for_select(Seed::TRADABLE_TO_VALUES, 'nowhere')) %span.help_inline - if current_member.location.blank? Don't forget to @@ -36,5 +33,11 @@ =succeed "." do = current_member.location =link_to "Change your location.", edit_member_registration_path + %span.help-block + Are you interested in trading or swapping seeds with other + #{Growstuff::Application.config.site_name} members? If you + list your seeds as available for trade, other members can + contact you to request seeds. You can list any conditions or + other information in the description, above. .form-actions = f.submit 'Save', :class => 'btn btn-primary' diff --git a/app/views/seeds/index.html.haml b/app/views/seeds/index.html.haml index b760cfe68..817ca0587 100644 --- a/app/views/seeds/index.html.haml +++ b/app/views/seeds/index.html.haml @@ -30,10 +30,9 @@ %td= seed.description %td= seed.quantity %td= seed.plant_before - %td= seed.tradable ? "Yes" : "" %td= seed.tradable_to %td - - if seed.tradable_to + - if seed.tradable? = seed.owner.location.blank? ? "unspecified" : seed.owner.location %td= link_to 'Details', seed, :class => 'btn btn-mini' - else diff --git a/app/views/seeds/show.html.haml b/app/views/seeds/show.html.haml index 18a7da6d9..88d2d6f0e 100644 --- a/app/views/seeds/show.html.haml +++ b/app/views/seeds/show.html.haml @@ -11,13 +11,9 @@ %p %b Plant before: = @seed.plant_before.to_s - %p - %b Tradable: - = @seed.tradable ? "Yes" : "No" %p %b Will trade to: - = @seed.tradable_to ? @seed.tradable_to : "nowhere" - - if @seed.tradable + = @seed.tradable_to - if @seed.owner.location.blank? (from unspecified location) - if current_member == @seed.owner @@ -25,7 +21,7 @@ - else (from = succeed ")" do - =@seed.owner.location + = @seed.owner.location %p %b Description: @@ -33,7 +29,7 @@ #{ @seed.description != "" ? @seed.description : "No description given." } - if current_member - - if @seed.tradable && current_member != @seed.owner + - if @seed.tradable? && current_member != @seed.owner %p = link_to "Request seeds", new_notification_path(:recipient_id => @seed.owner.id, :subject => "Interested in your #{@seed.crop} seeds"), :class => 'btn btn-primary' - else @@ -47,4 +43,4 @@ =link_to 'Delete', @seed, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' .span6 - = render :partial => "crops/index_card", :locals => { :crop => @seed.crop} + = render :partial => "crops/index_card", :locals => { :crop => @seed.crop } diff --git a/db/migrate/20130722050836_remove_tradable_from_seeds.rb b/db/migrate/20130722050836_remove_tradable_from_seeds.rb new file mode 100644 index 000000000..7e0457c10 --- /dev/null +++ b/db/migrate/20130722050836_remove_tradable_from_seeds.rb @@ -0,0 +1,9 @@ +class RemoveTradableFromSeeds < ActiveRecord::Migration + def up + remove_column :seeds, :tradable + end + + def down + add_column :seeds, :tradable, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index a55296e9f..2f4c40e91 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130718011247) do +ActiveRecord::Schema.define(:version => 20130722050836) do create_table "account_types", :force => true do |t| t.string "name", :null => false @@ -242,7 +242,6 @@ ActiveRecord::Schema.define(:version => 20130718011247) do t.date "plant_before" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false - t.boolean "tradable" t.string "tradable_to" end diff --git a/spec/factories/seeds.rb b/spec/factories/seeds.rb index ebafafe90..fcb1c15ca 100644 --- a/spec/factories/seeds.rb +++ b/spec/factories/seeds.rb @@ -9,8 +9,11 @@ FactoryGirl.define do plant_before "2013-07-15" factory :tradable_seed do - tradable true tradable_to "locally" end + + factory :untradable_seed do + tradable_to "nowhere" + end end end diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index 2b7083054..ad70c0e1b 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -12,7 +12,7 @@ describe Seed do context 'tradable' do it 'all three valid tradable_to values should work' do - ['locally', 'nationally', 'internationally', nil, ''].each do |t| + ['nowhere', 'locally', 'nationally', 'internationally', nil, ''].each do |t| @seed = FactoryGirl.build(:seed, :tradable_to => t) @seed.should be_valid end @@ -21,7 +21,26 @@ describe Seed do it 'should refuse invalid tradable_to values' do @seed = FactoryGirl.build(:seed, :tradable_to => 'not valid') @seed.should_not be_valid - @seed.errors[:tradable_to].should include("You may only trade seed locally, nationally, or internationally") + @seed.errors[:tradable_to].should include("You may only trade seed nowhere, locally, nationally, or internationally") + end + + it 'tradable? gives the right answers' do + @seed = FactoryGirl.create(:seed, :tradable_to => 'nowhere') + @seed.tradable?.should eq false + @seed = FactoryGirl.create(:seed, :tradable_to => 'locally') + @seed.tradable?.should eq true + @seed = FactoryGirl.create(:seed, :tradable_to => 'nationally') + @seed.tradable?.should eq true + @seed = FactoryGirl.create(:seed, :tradable_to => 'internationally') + @seed.tradable?.should eq true + end + + it 'recognises a tradable seed' do + FactoryGirl.create(:tradable_seed).tradable?.should == true + end + + it 'recognises an untradable seed' do + FactoryGirl.create(:untradable_seed).tradable?.should == false end end diff --git a/spec/views/seeds/edit.html.haml_spec.rb b/spec/views/seeds/edit.html.haml_spec.rb index d538ab57c..f4193d0ef 100644 --- a/spec/views/seeds/edit.html.haml_spec.rb +++ b/spec/views/seeds/edit.html.haml_spec.rb @@ -16,7 +16,6 @@ describe "seeds/edit" do assert_select "select#seed_crop_id", :name => "seed[crop_id]" assert_select "textarea#seed_description", :name => "seed[description]" assert_select "input#seed_quantity", :name => "seed[quantity]" - assert_select "input#seed_tradable", :name => "seed[tradable]" assert_select "select#seed_tradable_to", :name => "seed[tradable_to]" end end diff --git a/spec/views/seeds/index.html.haml_spec.rb b/spec/views/seeds/index.html.haml_spec.rb index a0ed699c9..a2902a08f 100644 --- a/spec/views/seeds/index.html.haml_spec.rb +++ b/spec/views/seeds/index.html.haml_spec.rb @@ -28,7 +28,7 @@ describe "seeds/index" do assert_select "tr>td", :text => @seed1.tradable_to, :count => 2 end - it "shows location of seed owner" do + it "shows location of seed owner" do assert_select "tr>td", :text => @owner.location, :count => 2 end end diff --git a/spec/views/seeds/new.html.haml_spec.rb b/spec/views/seeds/new.html.haml_spec.rb index 876119bbf..80d6090fa 100644 --- a/spec/views/seeds/new.html.haml_spec.rb +++ b/spec/views/seeds/new.html.haml_spec.rb @@ -15,7 +15,6 @@ describe "seeds/new" do assert_select "select#seed_crop_id", :name => "seed[crop_id]" assert_select "textarea#seed_description", :name => "seed[description]" assert_select "input#seed_quantity", :name => "seed[quantity]" - assert_select "input#seed_tradable", :name => "seed[tradable]" assert_select "select#seed_tradable_to", :name => "seed[tradable_to]" end end diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index de59664ce..223169114 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -25,7 +25,6 @@ describe "seeds/show" do it "shows tradable attributes" do render - rendered.should contain "Tradable: Yes" rendered.should contain "Will trade to: locally" end @@ -50,14 +49,13 @@ describe "seeds/show" do it "links to profile to set location" do render assert_select "a[href=#{url_for(edit_member_registration_path)}]", :text => "Set Location" - end - end it "shows button to send message" do render rendered.should contain "Request seeds" end + end end