article_test.rb 2.3 KB

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