Guest User

Untitled

a guest
Apr 26th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. require File.dirname(__FILE__) + '/../test_api_helper'
  2.  
  3. class CustomCollectionApiTest < Test::Unit::TestCase
  4. include ApiDocumentationSuite
  5.  
  6.  
  7. documentation('CustomCollection') do |controller|
  8.  
  9. controller.action :index do |doc|
  10. doc.description "Get a list of Custom Collections"
  11. doc.example 'List all collections' do
  12. collections = ShopifyAPI::CustomCollection.find(:all)
  13. assert_equal 1, collections.size
  14.  
  15. # Regenerate test case:
  16. #freeze('collections', collections)
  17. assert_equal 1, collections.size
  18. assert_equal ["body", "body_html", "handle", "id", "published_at", "title", "updated_at"], collections[0].attributes.keys.sort
  19. assert_equal "The best selling ipod ever", collections[0].body
  20. assert_equal "<p>The best selling ipod ever</p>", collections[0].body_html
  21. assert_equal "ipods", collections[0].handle
  22. assert_equal Time.parse('Sat Feb 02 00:00:00 UTC 2008'), collections[0].published_at
  23. assert_equal "IPods", collections[0].title
  24. end
  25. end
  26.  
  27.  
  28. controller.action :show do |doc|
  29. doc.description "Get a list of Custom Collections"
  30. doc.example 'Get a specific collection' do
  31. collection = ShopifyAPI::CustomCollection.find( collections(:ipods).id )
  32.  
  33. # Regenerate test case:
  34. #freeze('collection', collection)
  35. assert_equal ["body", "body_html", "handle", "id", "published_at", "title", "updated_at"], collection.attributes.keys.sort
  36. assert_equal 'The best selling ipod ever', collection.body
  37. assert_equal "<p>The best selling ipod ever</p>", collection.body_html
  38. assert_equal "ipods", collection.handle
  39. assert_equal Time.parse('Sat Feb 02 00:00:00 UTC 2008'), collection.published_at
  40. assert_equal "IPods", collection.title
  41. end
  42. end
  43.  
  44. controller.action :create do |doc|
  45. doc.description "Create a new custom collection"
  46. doc.example 'Create a collection with title Macbooks' do
  47. assert_difference 'Collection.count', +1 do
  48. collection = ShopifyAPI::CustomCollection.new( :title => 'Macbooks' )
  49. assert collection.save
  50. assert collection.valid?
  51. assert_equal 'Macbooks', collection.title
  52. end
  53. end
  54. end
  55.  
  56. controller.action :update do |doc|
  57. doc.description 'Update a existing custom collection'
  58. doc.example "Change the description of the IPod collection" do
  59. collection = ShopifyAPI::CustomCollection.find( collections(:ipods).id )
  60. collection.body = '5000 songs in your pocket'
  61. assert collection.save
  62.  
  63. collections(:featured).reload
  64.  
  65. # Regenerate test case:
  66. #freeze('collection', collection)
  67.  
  68. assert_equal ["body", "body_html", "handle", "id", "published_at", "title", "updated_at"], collection.attributes.keys.sort
  69. assert_equal "5000 songs in your pocket", collection.body
  70. assert_equal "<p>5000 songs in your pocket</p>", collection.body_html
  71. assert_equal "ipods", collection.handle
  72. assert_equal Time.parse('Sat Feb 02 00:00:00 UTC 2008'), collection.published_at
  73. assert_equal "IPods", collection.title
  74. end
  75. end
  76.  
  77. controller.action :destroy do |doc|
  78.  
  79. doc.example "Remove ipod custom collection" do
  80. assert_difference 'Collection.count', -1 do
  81. ShopifyAPI::CustomCollection.find( collections(:ipods).id ).destroy
  82. end
  83. end
  84.  
  85. end
  86. end
  87. end
Add Comment
Please, Sign In to add comment