From cecb3b1a32f5aa92d2cecdf8d76f8c7dd45d1e52 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Mon, 2 Sep 2013 14:02:18 -0400 Subject: [PATCH] Changing bike_status to bike_purporse --- app/components/bikes.rb | 4 ++-- .../bikes/javascripts/init_component.js | 2 +- .../user_logs/javascripts/init_component.js | 2 +- app/models/bike.rb | 10 +++++----- app/models/bike_purpose.rb | 9 +++++++++ app/models/bike_status.rb | 9 --------- app/models/user.rb | 4 ++-- .../20130902164600_bike_status_to_purpose.rb | 7 +++++++ db/schema.rb | 8 ++++---- db/seed/fixtures/bike_purposes.yml | 18 ++++++++++++++++++ db/seed/fixtures/bike_statuses.yml | 18 ------------------ spec/factories/bikes.rb | 2 +- 12 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 app/models/bike_purpose.rb delete mode 100644 app/models/bike_status.rb create mode 100644 db/migrate/20130902164600_bike_status_to_purpose.rb create mode 100644 db/seed/fixtures/bike_purposes.yml delete mode 100644 db/seed/fixtures/bike_statuses.yml diff --git a/app/components/bikes.rb b/app/components/bikes.rb index a7c42c3..3555c4d 100644 --- a/app/components/bikes.rb +++ b/app/components/bikes.rb @@ -26,7 +26,7 @@ class Bikes < Netzke::Basepack::Grid { :name => :wheel_size, :text => 'Wheel Size (in)'}, :value, { :id => :bike_condition__condition, :name => :bike_condition__condition, :text => 'Condition'}, - { :id => :bike_status__status, :name => :bike_status__status, :text => 'Status'}, + { :id => :bike_purpose__purpose, :name => :bike_purpose__purpose, :text => 'Purpose'}, { :name => :owner, :getter => lambda { |rec| user = rec.owner user.nil? ? "" : "#{user.first_name} #{user.last_name}" @@ -52,7 +52,7 @@ class Bikes < Netzke::Basepack::Grid { :name => :wheel_size, :field_label => 'Wheel Size (in)'}, { :name => :value, :field_label => 'Value'}, { :name => :bike_condition__condition, :field_label => 'Condition'}, - { :name => :bike_status__status, :field_label => 'Status'} + { :name => :bike_purpose__purpose, :field_label => 'Purpose'} ] end #override with nil to remove actions diff --git a/app/components/bikes/javascripts/init_component.js b/app/components/bikes/javascripts/init_component.js index fc44002..2171057 100644 --- a/app/components/bikes/javascripts/init_component.js +++ b/app/components/bikes/javascripts/init_component.js @@ -9,7 +9,7 @@ "bike_model__model", "bike_style__style", "bike_condition__condition", - "bike_status__status"] + "bike_purpose__purpose"] Ext.each(min_char_columns, function(column, index) { Ext.ComponentManager.get(column).editor.minChars = 1; }); diff --git a/app/components/user_logs/javascripts/init_component.js b/app/components/user_logs/javascripts/init_component.js index 05bde6c..d6b5d22 100644 --- a/app/components/user_logs/javascripts/init_component.js +++ b/app/components/user_logs/javascripts/init_component.js @@ -5,7 +5,7 @@ //due to Netzke bug, :min_chars attribute doesn't work var min_char_columns = [ - "user_action__status"] + "user_action__purpose"] Ext.each(min_char_columns, function(column, index) { Ext.ComponentManager.get(column).editor.minChars = 1; }); diff --git a/app/models/bike.rb b/app/models/bike.rb index c29981d..f33b6fc 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -1,7 +1,7 @@ class Bike < ActiveRecord::Base acts_as_loggable attr_accessible :shop_id, :serial_number, :bike_brand_id, :bike_model_id, :color, :bike_style_id, :seat_tube_height, - :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_status_id + :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_purpose_id has_many :transactions @@ -11,7 +11,7 @@ class Bike < ActiveRecord::Base belongs_to :bike_model belongs_to :bike_style belongs_to :bike_condition - belongs_to :bike_status + belongs_to :bike_purpose validates :shop_id, :presence => true, :uniqueness => true, :length => { :minimum => 3 } validates :serial_number, :length => { :minimum => 3 } @@ -24,7 +24,7 @@ class Bike < ActiveRecord::Base validates :wheel_size, :presence => true #validates :value, :presence => true validates :bike_condition_id, :presence => true - validates :bike_status_id, :presence => true + validates :bike_purpose_id, :presence => true self.per_page = 15 @@ -46,8 +46,8 @@ class Bike < ActiveRecord::Base self.bike_condition end - def status - self.bike_status + def purpose + self.bike_purpose end def to_s diff --git a/app/models/bike_purpose.rb b/app/models/bike_purpose.rb new file mode 100644 index 0000000..d5ec930 --- /dev/null +++ b/app/models/bike_purpose.rb @@ -0,0 +1,9 @@ +class BikePurpose < ActiveRecord::Base + attr_accessible :purpose + + belongs_to :bike + + def to_s + self.purpose + end +end diff --git a/app/models/bike_status.rb b/app/models/bike_status.rb deleted file mode 100644 index 8ec30aa..0000000 --- a/app/models/bike_status.rb +++ /dev/null @@ -1,9 +0,0 @@ -class BikeStatus < ActiveRecord::Base - attr_accessible :status - - belongs_to :bike - - def to_s - self.status - end -end diff --git a/app/models/user.rb b/app/models/user.rb index 47f100a..4abeda3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -45,7 +45,7 @@ class User < ActiveRecord::Base ### TODO methods below probably belong somewhere else def completed_build_bikes - status_id = BikeStatus.find_by_status("BUILDBIKE").id + purpose_id = BikePurpose.find_by_purpose("BUILDBIKE").id Bike.find_by_sql(" SELECT * FROM bikes @@ -54,7 +54,7 @@ class User < ActiveRecord::Base FROM transactions WHERE customer_id = #{self.id} ) AS transactions ON bikes.id = transactions.bike_id - WHERE bike_status_id = #{status_id}") + WHERE bike_purpose_id = #{purpose_id}") end def total_credits diff --git a/db/migrate/20130902164600_bike_status_to_purpose.rb b/db/migrate/20130902164600_bike_status_to_purpose.rb new file mode 100644 index 0000000..dc83e28 --- /dev/null +++ b/db/migrate/20130902164600_bike_status_to_purpose.rb @@ -0,0 +1,7 @@ +class BikeStatusToPurpose < ActiveRecord::Migration + def change + rename_column :bikes, :bike_status_id, :bike_purpose_id + rename_column :bike_statuses, :status, :purpose + rename_table :bike_statuses, :bike_purposes + end +end diff --git a/db/schema.rb b/db/schema.rb index dcd996f..cb1b3c9 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 => 20130816015219) do +ActiveRecord::Schema.define(:version => 20130902164600) do create_table "bike_actions", :force => true do |t| t.string "action", :limit => 128, :null => false @@ -34,8 +34,8 @@ ActiveRecord::Schema.define(:version => 20130816015219) do t.integer "bike_brand_id", :null => false end - create_table "bike_statuses", :force => true do |t| - t.string "status", :null => false + create_table "bike_purposes", :force => true do |t| + t.string "purpose", :null => false t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end @@ -57,7 +57,7 @@ ActiveRecord::Schema.define(:version => 20130816015219) do t.integer "wheel_size" t.float "value" t.integer "bike_condition_id", :null => false - t.integer "bike_status_id", :null => false + t.integer "bike_purpose_id", :null => false t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "shop_id" diff --git a/db/seed/fixtures/bike_purposes.yml b/db/seed/fixtures/bike_purposes.yml new file mode 100644 index 0000000..f133eb6 --- /dev/null +++ b/db/seed/fixtures/bike_purposes.yml @@ -0,0 +1,18 @@ +undetermined: + id: 1 + purpose: UNDETERMINED +scrap: + id: 2 + purpose: SCRAP +parts: + id: 3 + purpose: PARTS +storage: + id: 4 + purpose: STORAGE +buildbike: + id: 5 + purpose: BUILDBIKE +sale: + id: 6 + purpose: SALE diff --git a/db/seed/fixtures/bike_statuses.yml b/db/seed/fixtures/bike_statuses.yml deleted file mode 100644 index fb697fa..0000000 --- a/db/seed/fixtures/bike_statuses.yml +++ /dev/null @@ -1,18 +0,0 @@ -undetermined: - id: 1 - status: UNDETERMINED -scrap: - id: 2 - status: SCRAP -parts: - id: 3 - status: PARTS -storage: - id: 4 - status: STORAGE -buildbike: - id: 5 - status: BUILDBIKE -sale: - id: 6 - status: SALE diff --git a/spec/factories/bikes.rb b/spec/factories/bikes.rb index ffe34e4..15ae066 100644 --- a/spec/factories/bikes.rb +++ b/spec/factories/bikes.rb @@ -17,6 +17,6 @@ FactoryGirl.define do wheel_size 27 value 100 bike_condition_id 1 - bike_status_id 1 + bike_purpose_id 1 end end