spec/zunnit_spec.rb in zunnit-0.3.1 vs spec/zunnit_spec.rb in zunnit-0.3.2
- old
+ new
@@ -79,17 +79,43 @@
:item_id => "20275919"
validate_response(response, :clusters)
end
end
-describe "post" do
+ describe "post" do
+ it "should return status 200 when add an item" do
+ intercept_resquest_to :post,
+ :action => :action_items_add,
+ :params => { :item_id => "2121", :item_text => "text" },
+ :response => { :status => 200, :body => {:msg => 'Ok', :status => 200}.to_json }
-end
+ validate_response Zunnit.api.post :action_items_add, :item_id => "2121", :item_text => "text"
+ end
-private
-def validate_response(response, results_key)
-response[:status].should == 200
-response[:msg].should == "Ok"
-response[results_key].size.should >= 1
-end
+ it "should return status 200 when user clip an item" do
+ intercept_resquest_to :post,
+ :action => :action_items_rate,
+ :params => { :item_id => "2121", :user_id => "2121", :rating => 1 },
+ :response => { :status => 200, :body => {:msg => 'Ok', :status => 200}.to_json }
+
+ validate_response Zunnit.api.post :action_items_rate, :item_id => "2121", :user_id => "2121"
+ end
+
+ end
+
+ private
+ def validate_response(response, results_key = nil)
+ response[:status].should == 200
+ response[:msg].should == "Ok"
+ response[results_key].size.should >= 1 if results_key
+ end
+
+ def intercept_resquest_to(method, options)
+ action = options.delete(:action)
+ params = options.delete(:params)
+ response = options.delete(:response)
+ uri = "#{Zunnit::URL}#{Zunnit.client}#{Zunnit.actions[action]}"
+ uri = uri + params.map {|k,v| "#{k}=#{v}" }.join("&") unless method.to_s =~ /post|put/
+ FakeWeb.register_uri(method, uri, response)
+ end
end