This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :author, String | |
property :price, Decimal | |
end | |
class User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order | |
include DataMapper::Resource | |
property :id, Serial, key: true | |
property :status, Enum[:new, :ready, :paid, :shipped, :closed, :canceled] | |
belongs_to :buyer, 'User' | |
has n, :items | |
has 1, :payment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buyer = current_user | |
order = Order.make buyer | |
#At this moment: | |
#order.shipping_address == buyers_address | |
#order.status == :new | |
order.make_item book1, 2 | |
order.make_item book2, 3 | |
order.mark_as_ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
order = Order.get(buyer, params[:id]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@all_orders = current_user.orders.active |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@all_orders = Order.active_orders(user) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
order = ... | |
stub(orders = Object.new).active {[order]} | |
stub(user = Object.new).orders {orders} | |
stub(UserSession).current_user {user} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
order = ... | |
stub(UserSession).current_user {user} | |
stub(Order).active_orders(user){[order]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderPresenter < Struct.new(:order) | |
def render_items | |
order.items.map do |item| | |
item_row item | |
end.join("") | |
end | |
private | |
def item_row item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PaymentService | |
def self.process order, credit_card | |
with_transaction do | |
order.make_payment mask_card(credit_card) | |
make_remote_call credit_card, order.payment | |
end | |
end | |
... | |
end |