diff --git a/full-examples/rest_from_scratch/part_3/app/controllers/baskets_controller.rb b/full-examples/rest_from_scratch/part_3/app/controllers/baskets_controller.rb index a49d309c..ac816305 100644 --- a/full-examples/rest_from_scratch/part_3/app/controllers/baskets_controller.rb +++ b/full-examples/rest_from_scratch/part_3/app/controllers/baskets_controller.rb @@ -16,6 +16,15 @@ def create render :text => "", :status => 201, :location => basket_url(@basket) end + def update + @basket = Basket.find(params[:id]) + params[: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 diff --git a/full-examples/rest_from_scratch/part_3/config/routes.rb b/full-examples/rest_from_scratch/part_3/config/routes.rb index f57291b3..a386c088 100644 --- a/full-examples/rest_from_scratch/part_3/config/routes.rb +++ b/full-examples/rest_from_scratch/part_3/config/routes.rb @@ -6,6 +6,8 @@ resources :items + match "baskets/:id", :controller => :baskets, :action => :update, :conditions => {:method => :patch} + # The priority is based upon order of creation: # first created -> highest priority. diff --git a/full-examples/rest_from_scratch/part_3/spec/client/buying_process.rb b/full-examples/rest_from_scratch/part_3/spec/client/buying_process.rb index 0b555a6a..e737fee2 100644 --- a/full-examples/rest_from_scratch/part_3/spec/client/buying_process.rb +++ b/full-examples/rest_from_scratch/part_3/spec/client/buying_process.rb @@ -15,8 +15,9 @@ def self.run Restfulie::Common::Logger.logger.level = Logger::ERROR goal = BuyingProcess.new("Rest", "Calpis") result = Restfulie::Mikyung.new.achieve(goal).run + result.response.code.should == 200 - result.payment.price.should == "410.0" + result.payment.amount.should == 410.0 puts "Goal Achieved" end end