removed tradable boolean field

we're now relying just on the "tradable_to" field, which is clearer.
This commit is contained in:
Skud
2013-07-22 15:47:25 +10:00
parent 610b100f7f
commit 3a96cd96df
13 changed files with 96 additions and 65 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,9 @@
class RemoveTradableFromSeeds < ActiveRecord::Migration
def up
remove_column :seeds, :tradable
end
def down
add_column :seeds, :tradable, :boolean
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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