Permalink
Browse files

use "accepter" instead of "fulfiller"

  • Loading branch information...
1 parent adcb4a9 commit 35193114a102d4da8c5d105de38a062cad00528f John Hyland committed Sep 24, 2010
View
@@ -1,11 +1,11 @@
class Order < ActiveRecord::Base
belongs_to :orderer, :class_name => "User"
- belongs_to :fulfiller, :class_name => "User"
+ belongs_to :accepter, :class_name => "User"
has_many :ordered_items, :dependent => :destroy
has_many :items, :through => :ordered_items
accepts_nested_attributes_for :items
- scope :fulfilled, where('fulfiller_id is not null')
+ scope :accepted, where('accepter_id is not null')
validates_presence_of :orderer
validate :must_have_items
@@ -22,7 +22,7 @@ def must_have_valid_date
end
def initialize_cost
- self.cost = self.expected_cost if self.fulfilled? and self.cost.nil?
+ self.cost = self.expected_cost if self.accepted? and self.cost.nil?
end
def add_item (item)
@@ -34,7 +34,7 @@ def expected_cost
self.ordered_items.collect(&:cost).sum
end
- def fulfilled?
- !self.fulfiller_id.nil?
+ def accepted?
+ !self.accepter_id.nil?
end
end
View
@@ -1,5 +1,5 @@
class User < ActiveRecord::Base
- has_many :fulfilled_orders, :class_name => 'Order', :foreign_key => 'fulfiller_id'
+ has_many :accepted_orders, :class_name => 'Order', :foreign_key => 'accepter_id'
has_many :placed_orders, :class_name => 'Order', :foreign_key => 'orderer_id'
# Include default devise modules. Others available are:
@@ -30,9 +30,9 @@ def balance
# thing that will work for now. Refactor when scaling becomes an issue.
payments_made = Payment.where(:payer_id => self.id).collect(&:amount).sum
payments_received = Payment.where(:recipient_id => self.id).collect(&:amount).sum
- orders_placed = Order.fulfilled.where(:orderer_id => self.id).collect(&:cost).sum
- orders_fulfilled = Order.fulfilled.where(:fulfiller_id => self.id).collect(&:cost).sum
+ orders_placed = Order.accepted.where(:orderer_id => self.id).collect(&:cost).sum
+ orders_accepted = Order.accepted.where(:accepter_id => self.id).collect(&:cost).sum
- (payments_made + orders_fulfilled - payments_received - orders_placed).to_f
+ (payments_made + orders_accepted - payments_received - orders_placed).to_f
end
end
@@ -3,7 +3,7 @@
= @order.orderer.name
%p
%b Accepted by:
- = @order.fulfiller.nil? ? 'nobody' : @order.fulfiller.name
+ = @order.accepter.nil? ? 'nobody' : @order.accepter.name
%p
%b Items:
%ul
@@ -0,0 +1,9 @@
+class ChangeFulfillerToAccepter < ActiveRecord::Migration
+ def self.up
+ rename_column :orders, :fulfiller_id, :accepter_id
+ end
+
+ def self.down
+ rename_column :orders, :accepter_id, :fulfiller_id
+ end
+end
View
@@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20100908163253) do
+ActiveRecord::Schema.define(:version => 20100920160349) do
create_table "items", :force => true do |t|
t.string "name"
@@ -30,7 +30,7 @@
create_table "orders", :force => true do |t|
t.integer "orderer_id"
- t.integer "fulfiller_id"
+ t.integer "accepter_id"
t.date "date"
t.datetime "created_at"
t.datetime "updated_at"
View
@@ -15,6 +15,8 @@
Order.blueprint do
orderer { User.make }
+ ordered_items { |order| [ OrderedItem.make(:order => order) ] }
+ date { Time.now }
end
Sham.cost { |n| n / 2.0 }
View
@@ -1,17 +1,17 @@
require 'spec_helper'
describe Order do
- context '.fulfilled' do
- it 'should return all fulfilled orders' do
+ context '.accepted' do
+ it 'should return all accepted orders' do
alice = User.make
bob = User.make
- order1 = Order.make(:orderer => alice, :fulfiller => bob)
- order2 = Order.make(:orderer => bob, :fulfiller => nil)
- order3 = Order.make(:orderer => bob, :fulfiller => alice)
+ order1 = Order.make(:orderer => alice, :accepter => bob)
+ order2 = Order.make(:orderer => bob, :accepter => nil)
+ order3 = Order.make(:orderer => bob, :accepter => alice)
- Order.fulfilled.should have(2).fulfilled_orders
- Order.fulfilled.should include(order1, order3)
+ Order.accepted.should have(2).accepted_orders
+ Order.accepted.should include(order1, order3)
end
end
@@ -27,13 +27,13 @@
end
end
- context '#fulfilled?' do
- it "should return false if the order is not fulfilled" do
- Order.make(:fulfiller => nil).should_not be_fulfilled
+ context '#accepted?' do
+ it "should return false if the order is not accepted" do
+ Order.make(:accepter => nil).should_not be_accepted
end
- it "should return true if the order is fulfilled" do
- Order.make(:fulfiller => User.make).should be_fulfilled
+ it "should return true if the order is accepted" do
+ Order.make(:accepter => User.make).should be_accepted
end
end
@@ -54,15 +54,15 @@
@order.save
end
- context "before the order is fulfilled" do
+ context "before the order is accepted" do
it "should be nil" do
@order.cost.should be_nil
end
end
- context "after the order is fulfilled" do
+ context "after the order is accepted" do
before do
- @order.fulfiller = User.make
+ @order.accepter = User.make
@order.save
end
View
@@ -6,10 +6,10 @@
@bob = User.make
@charlie = User.make
- Order.make(:orderer => @bob, :fulfiller => @alice, :cost => 5)
- Order.make(:orderer => @alice, :fulfiller => @charlie, :cost => 3)
- Order.make(:orderer => @alice, :fulfiller => @charlie, :cost => 5)
- Order.make(:orderer => @alice, :fulfiller => nil, :cost => nil)
+ Order.make(:orderer => @bob, :accepter => @alice, :cost => 5)
+ Order.make(:orderer => @alice, :accepter => @charlie, :cost => 3)
+ Order.make(:orderer => @alice, :accepter => @charlie, :cost => 5)
+ Order.make(:orderer => @alice, :accepter => nil, :cost => nil)
Payment.make(:payer => @bob, :recipient => @charlie, :amount => 3)
end

0 comments on commit 3519311

Please sign in to comment.