Guest User

Untitled

a guest
Jul 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. require File.expand_path(File.dirname(__FILE__) + '/acceptance_helper')
  2.  
  3.  
  4. describe "Finding a phone" do
  5.  
  6. before do
  7. 5.times { make_phone! }
  8. 5.times { Plan.make }
  9. @phones = Phone.find(:all)
  10. @plan = Plan.find(:all)
  11. end
  12.  
  13. after do
  14. Phone.destroy_all
  15. Plan.destroy_all
  16. end
  17.  
  18. it "should Find Phones" do
  19. get "/phones.json"
  20. result = ActiveSupport::JSON.decode(last_response.body)
  21. result.should have_key("phones")
  22. result["phones"].length.should eql(5)
  23. end
  24.  
  25. it "should Find a Phone" do
  26. get "/phones/#{@phones.first.id}.json"
  27. result = ActiveSupport::JSON.decode(last_response.body)
  28. result.should have_key("phone")
  29. result["phone"]["model"].should eql(@phones.first.name)
  30. end
  31.  
  32. end
  33.  
  34. describe "Creating a phone" do
  35.  
  36. before do
  37. @plan = Plan.make
  38. end
  39.  
  40. it "should create Phone successfully" do
  41. @attributes = {
  42. :manufacturer_name => "Nokia",
  43. :model => Sham.name,
  44. :url => Sham.url,
  45. :features_attributes => ["First feature", "Second Feature"],
  46. :plans_attributes => [{:plan_id => @plan.id, :monthlyHandSetCost => 20}]
  47. }
  48. post "/phones.json", :phone => @attributes
  49. result = ActiveSupport::JSON.decode(last_response.body)
  50. result.should have_key("phone")
  51. result["phone"]["model"].should eql(@attributes[:model])
  52. end
  53.  
  54. it "should create Phone unsuccessfully" do
  55. @attributes = {
  56. :manufacturer_name => "Nokia",
  57. }
  58. post "/phones.json", :phone => @attributes
  59. result = ActiveSupport::JSON.decode(last_response.body)
  60. result.should have_key("errors")
  61. result["errors"]["phone"]["name"].should include("can't be blank")
  62. result["errors"]["phone"]["url"].should include("can't be blank")
  63. end
  64. end
  65.  
  66. describe "Updating a phone" do
  67. it "should update a Phone successfully" do
  68. @phone = make_phone!
  69. put "/phones/#{@phone.id}.json", :phone => { :model => "Foo" }
  70. result = ActiveSupport::JSON.decode(last_response.body)
  71. result.should have_key("phone")
  72. result["phone"]["model"].should eql("Foo")
  73. end
  74. end
Add Comment
Please, Sign In to add comment