article_test.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. require 'test_helper'
  2. class ArticleTest < Test::Unit::TestCase
  3. def test_create_article
  4. fake "blogs/1008414260/articles", :method => :post, :body => load_fixture('article')
  5. article = ShopifyAPI::Article.new(:blog_id => 1008414260)
  6. article.save
  7. assert_equal "First Post", article.title
  8. end
  9. def test_get_article
  10. fake "articles/6242736", :method => :get, :body => load_fixture('article')
  11. article = ShopifyAPI::Article.find(6242736)
  12. assert_equal "First Post", article.title
  13. assert_equal 1008414260, article.blog_id
  14. end
  15. def test_get_articles
  16. fake "articles", :method => :get, :body => load_fixture('articles')
  17. articles = ShopifyAPI::Article.all
  18. assert_equal 3, articles.length
  19. assert_equal 1008414260, articles.first.blog_id
  20. end
  21. def test_get_articles_namespaced
  22. fake "blogs/1008414260/articles", :method => :get, :body => load_fixture('articles')
  23. articles = ShopifyAPI::Article.find(:all, :params => {:blog_id => 1008414260})
  24. assert_equal 3, articles.length
  25. assert_equal 1008414260, articles.first.blog_id
  26. end
  27. def test_get_article_namespaced
  28. fake "blogs/1008414260/articles/6242736", :method => :get, :body => load_fixture('article')
  29. article = ShopifyAPI::Article.find(6242736, :params => {:blog_id => 1008414260})
  30. assert_equal "First Post", article.title
  31. assert_equal 1008414260, article.blog_id
  32. end
  33. def test_get_authors
  34. fake "articles/authors", :method => :get, :body => load_fixture('authors')
  35. authors = ShopifyAPI::Article.authors
  36. assert_equal "Shopify", authors.first
  37. assert_equal "development shop", authors.last
  38. end
  39. def test_get_authors_for_blog_id
  40. fake "blogs/1008414260/articles/authors", :method => :get, :body => load_fixture('authors')
  41. authors = ShopifyAPI::Article.authors(:blog_id => 1008414260)
  42. assert_equal 3, authors.length
  43. end
  44. def test_get_tags
  45. fake "articles/tags", :method => :get, :body => load_fixture('tags')
  46. tags = ShopifyAPI::Article.tags
  47. assert_equal "consequuntur", tags.first
  48. assert_equal "repellendus", tags.last
  49. end
  50. def test_get_tags_for_blog_id
  51. fake "blogs/1008414260/articles/tags", :method => :get, :body => load_fixture('tags')
  52. tags = ShopifyAPI::Article.tags(:blog_id => 1008414260)
  53. assert_equal "consequuntur", tags.first
  54. assert_equal "repellendus", tags.last
  55. end
  56. def test_get_popular_tags
  57. fake "articles/tags.json?limit=1&popular=1", :extension => false, :method => :get, :body => load_fixture('tags')
  58. tags = ShopifyAPI::Article.tags(:popular => 1, :limit => 1)
  59. assert_equal 3, tags.length
  60. end
  61. end