Skip to content

Commit

Permalink
adding payment and basket into the game
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Aug 30, 2010
1 parent f29d79d commit 4333fa9
Show file tree
Hide file tree
Showing 40 changed files with 800 additions and 33 deletions.
50 changes: 20 additions & 30 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# encoding: UTF-8

require 'rubygems'
require 'rubygems/specification'
require 'rake'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rspec'
require File.expand_path('lib/restfulie')

GEM = "restfulie"
Expand Down Expand Up @@ -76,25 +75,25 @@ namespace :test do
end
end

# namespace :spec do
# spec_opts = ['--options', File.join(File.dirname(__FILE__) , 'spec', 'units', 'spec.opts')]
# Spec::Rake::SpecTask.new(:all) do |t|
# t.spec_files = FileList['spec/units/**/*_spec.rb']
# t.spec_opts = spec_opts
# end
# Spec::Rake::SpecTask.new(:common) do |t|
# t.spec_files = FileList['spec/common/**/*_spec.rb']
# t.spec_opts = spec_opts
# end
# Spec::Rake::SpecTask.new(:client) do |t|
# t.spec_files = FileList['spec/units/client/**/*_spec.rb']
# t.spec_opts = spec_opts
# end
# Spec::Rake::SpecTask.new(:server) do |t|
# t.spec_files = FileList['spec/units/server/**/*_spec.rb']
# t.spec_opts = spec_opts
# end
# end
task :spec do
# spec_opts = ['--options', File.join(File.dirname(__FILE__) , 'spec', 'units', 'spec.opts')]
RSpec::Core::RakeTask.new(:all) do |t|
t.spec_files = FileList['spec/units/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:common) do |t|
t.spec_files = FileList['spec/common/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:client) do |t|
t.spec_files = FileList['spec/units/client/**/*_spec.rb']
t.spec_opts = spec_opts
end
Spec::Rake::SpecTask.new(:server) do |t|
t.spec_files = FileList['spec/units/server/**/*_spec.rb']
t.spec_opts = spec_opts
end
end

# namespace :rcov do
# Spec::Rake::SpecTask.new('rcov') do |t|
Expand All @@ -116,15 +115,6 @@ namespace :test do
Rake::Task["test:integration"].invoke()
Rake::Task["test:examples"].invoke()
end
task :common do
start_server_and_invoke_test('test:spec:common')
end
task :client do
start_server_and_invoke_test('test:spec:client')
end
task :server do
start_server_and_invoke_test('test:spec:server')
end
task :rcov do
start_server_and_invoke_test('test:rcov:rcov')
end
Expand Down
3 changes: 1 addition & 2 deletions full-examples/rest_from_scratch/part_1/autotest/discover.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
Autotest.add_discovery { "rspec2" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class BasketsController < ApplicationController


include Restfulie::Server::ActionController::Base

respond_to :xml, :json

def create
@basket = Basket.new
params[:basket][:items].each do |item|
@basket.items << Item.find(item[:id])
end
@basket.save
render :text => "", :status => 201, :location => basket_url(@basket)
end

def show
@basket = Basket.find(params[:id])
respond_with @basket
end


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class PaymentsController < ApplicationController

include Restfulie::Server::ActionController::Base

respond_to :xml, :json

def create
@payment = Basket.find(params[:basket_id]).payments.create(params[:payment])
render :text => "", :status => 201, :location => basket_payment_url(@payment.basket, @payment)
end

def show
@payment = Payment.find(params[:id])
respond_with @payment
end


end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BasketsHelper
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PaymentsHelper
end
2 changes: 2 additions & 0 deletions full-examples/rest_from_scratch/part_2/app/models/basket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Basket < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions full-examples/rest_from_scratch/part_2/app/models/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Payment < ActiveRecord::Base
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_for(@basket) do |f| %>
<% if @basket.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@basket.errors.count, "error") %> prohibited this basket from being saved:</h2>

<ul>
<% @basket.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing basket</h1>

<%= render 'form' %>
<%= link_to 'Show', @basket %> |
<%= link_to 'Back', baskets_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>Listing baskets</h1>

<table>
<tr>
<th></th>
<th></th>
<th></th>
</tr>

<% @baskets.each do |basket| %>
<tr>
<td><%= link_to 'Show', basket %></td>
<td><%= link_to 'Edit', edit_basket_path(basket) %></td>
<td><%= link_to 'Destroy', basket, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Basket', new_basket_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New basket</h1>

<%= render 'form' %>
<%= link_to 'Back', baskets_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p id="notice"><%= notice %></p>


<%= link_to 'Edit', edit_basket_path(@basket) %> |
<%= link_to 'Back', baskets_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= form_for(@payment) do |f| %>
<% if @payment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@payment.errors.count, "error") %> prohibited this payment from being saved:</h2>

<ul>
<% @payment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :cardnumber %><br />
<%= f.text_field :cardnumber %>
</div>
<div class="field">
<%= f.label :cardholder %><br />
<%= f.text_field :cardholder %>
</div>
<div class="field">
<%= f.label :amount %><br />
<%= f.text_field :amount %>
</div>
<div class="field">
<%= f.label :basket_id %><br />
<%= f.text_field :basket_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing payment</h1>

<%= render 'form' %>
<%= link_to 'Show', @payment %> |
<%= link_to 'Back', payments_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<h1>Listing payments</h1>

<table>
<tr>
<th>Cardnumber</th>
<th>Cardholder</th>
<th>Amount</th>
<th>Basket</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @payments.each do |payment| %>
<tr>
<td><%= payment.cardnumber %></td>
<td><%= payment.cardholder %></td>
<td><%= payment.amount %></td>
<td><%= payment.basket_id %></td>
<td><%= link_to 'Show', payment %></td>
<td><%= link_to 'Edit', edit_payment_path(payment) %></td>
<td><%= link_to 'Destroy', payment, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Payment', new_payment_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New payment</h1>

<%= render 'form' %>
<%= link_to 'Back', payments_path %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p id="notice"><%= notice %></p>

<p>
<b>Cardnumber:</b>
<%= @payment.cardnumber %>
</p>

<p>
<b>Cardholder:</b>
<%= @payment.cardholder %>
</p>

<p>
<b>Amount:</b>
<%= @payment.amount %>
</p>

<p>
<b>Basket:</b>
<%= @payment.basket_id %>
</p>


<%= link_to 'Edit', edit_payment_path(@payment) %> |
<%= link_to 'Back', payments_path %>
4 changes: 4 additions & 0 deletions full-examples/rest_from_scratch/part_2/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
RestFromScratch::Application.routes.draw do
resources :payments

resources :baskets

resources :items

# The priority is based upon order of creation:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateBaskets < ActiveRecord::Migration
def self.up
create_table :baskets do |t|

t.timestamps
end
end

def self.down
drop_table :baskets
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreatePayments < ActiveRecord::Migration
def self.up
create_table :payments do |t|
t.string :cardnumber
t.string :cardholder
t.decimal :amount
t.integer :basket_id

t.timestamps
end
end

def self.down
drop_table :payments
end
end
16 changes: 15 additions & 1 deletion full-examples/rest_from_scratch/part_2/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20100830171258) do
ActiveRecord::Schema.define(:version => 20100830180203) do

create_table "baskets", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "items", :force => true do |t|
t.string "name"
Expand All @@ -19,4 +24,13 @@
t.datetime "updated_at"
end

create_table "payments", :force => true do |t|
t.string "cardnumber"
t.string "cardholder"
t.decimal "amount"
t.integer "basket_id"
t.datetime "created_at"
t.datetime "updated_at"
end

end
Loading

0 comments on commit 4333fa9

Please sign in to comment.