reviewed 0.4.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -1
  3. data/lib/reviewed/article.rb +0 -1
  4. data/lib/reviewed/attachable.rb +14 -7
  5. data/lib/reviewed/product.rb +0 -1
  6. data/lib/reviewed/version.rb +1 -1
  7. data/spec/attachable_spec.rb +22 -0
  8. data/spec/fixtures/vcr/Reviewed_Article/associations/attachments/assigns_attachments_to_the_correct_class.yml +338 -289
  9. data/spec/fixtures/vcr/Reviewed_Article/associations/attachments/does_not_has_many_attachments.yml +237 -245
  10. data/spec/fixtures/vcr/Reviewed_Article/associations/attachments/does_not_have_any_matching_attachments.yml +280 -289
  11. data/spec/fixtures/vcr/Reviewed_Article/associations/attachments/finds_attachments_by_tag.yml +281 -301
  12. data/spec/fixtures/vcr/Reviewed_Article/associations/attachments/gets_gallery_attachments.yml +340 -324
  13. data/spec/fixtures/vcr/Reviewed_Article/associations/deals/has_many_deals.yml +237 -245
  14. data/spec/fixtures/vcr/Reviewed_Article/associations/pages/has_many_pages.yml +237 -245
  15. data/spec/fixtures/vcr/Reviewed_Article/associations/products/has_many_products.yml +237 -245
  16. data/spec/fixtures/vcr/Reviewed_Article/associations/products/returns_products_of_the_correct_class.yml +237 -245
  17. data/spec/fixtures/vcr/Reviewed_Article/associations/related_articles/has_many_related_articles.yml +237 -245
  18. data/spec/fixtures/vcr/Reviewed_Article/does_not_request_for_an_attachment_if_it_can_be_found_in_attributes.yml +387 -0
  19. data/spec/fixtures/vcr/Reviewed_Article/fetches_all_attachments_when_no_tag_is_asked_for.yml +195 -0
  20. data/spec/fixtures/vcr/Reviewed_Article/fetches_attachments_when_non-existent.yml +137 -0
  21. data/spec/fixtures/vcr/Reviewed_Article/fetches_when_a_tag_is_not_in_pre-loaded_set.yml +75 -0
  22. data/spec/fixtures/vcr/Reviewed_Article/fetches_when_an_tag_is_not_in_pre-loaded_set.yml +75 -0
  23. data/spec/fixtures/vcr/Reviewed_Article/find_page/finds_a_page_with_a_matching_slug.yml +377 -394
  24. data/spec/fixtures/vcr/Reviewed_Article/primary_product/returns_a_product_of_the_correct_class.yml +471 -487
  25. data/spec/fixtures/vcr/Reviewed_Article/primary_product/returns_nil_if_does_not_respond_to_products.yml +471 -487
  26. data/spec/fixtures/vcr/Reviewed_Article/primary_product/returns_the_primary_product.yml +471 -487
  27. data/spec/fixtures/vcr/Reviewed_Article/returns_local_attachments_when_available.yml +137 -0
  28. data/spec/fixtures/vcr/Reviewed_Article/sets_DEFAULT_ATTACHMENTS.yml +75 -0
  29. data/spec/fixtures/vcr/Reviewed_Client/_perform/request_params/not_set/has_nil_query_params.yml +138 -195
  30. data/spec/fixtures/vcr/Reviewed_Client/_perform/request_params/set/merges_quest_params.yml +48 -71
  31. data/spec/fixtures/vcr/Reviewed_Collection/collection_data/fetches_the_first_page_by_default.yml +73 -113
  32. data/spec/fixtures/vcr/Reviewed_Collection/collection_data/is_enumerable.yml +73 -113
  33. data/spec/fixtures/vcr/Reviewed_Collection/next_page/fetches_the_next_page_of_results.yml +140 -197
  34. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/indicates_if_the_page_number_is_out_of_bounds.yml +73 -113
  35. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/indicates_whether_this_is_the_first_or_last_page.yml +73 -113
  36. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/returns_the_limit_value_max_per_page_.yml +73 -113
  37. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/returns_the_number_of_entries_on_the_current_page.yml +73 -113
  38. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/returns_the_offset.yml +73 -113
  39. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/returns_the_total_item_count.yml +73 -113
  40. data/spec/fixtures/vcr/Reviewed_Collection/page_attributes_pagination_/returns_the_total_number_of_pages.yml +73 -113
  41. data/spec/fixtures/vcr/Reviewed_Collection/previous_page/fetches_the_previous_page_of_results.yml +210 -307
  42. data/spec/fixtures/vcr/Reviewed_Collection/previous_page/returns_nil_if_there_is_no_previous_page.yml +73 -113
  43. data/spec/fixtures/vcr/Reviewed_Product/associations/attachments/does_not_have_any_matching_attachments.yml +98 -125
  44. data/spec/fixtures/vcr/Reviewed_Product/associations/attachments/matches_attachments_by_tag_properly.yml +98 -136
  45. data/spec/fixtures/vcr/Reviewed_Product/associations/attachments/no_longer_has_many_attachments.yml +55 -81
  46. data/spec/fixtures/vcr/Reviewed_Product/associations/attachments/returns_attachments_by_tag.yml +98 -136
  47. data/spec/fixtures/vcr/Reviewed_Product/associations/attachments/returns_attachments_of_the_correct_class.yml +98 -125
  48. data/spec/fixtures/vcr/Reviewed_Product/manufacturer_specs/has_many_manufacturer_specs.yml +55 -81
  49. data/spec/fixtures/vcr/Reviewed_Product/manufacturer_specs/returns_attachments_of_the_correct_class.yml +55 -81
  50. data/spec/fixtures/vcr/Reviewed_Request/_where/filters_collections_using_other_supported_options.yml +49 -67
  51. data/spec/fixtures/vcr/Reviewed_Request/_where/returns_a_collection.yml +138 -195
  52. data/spec/fixtures/vcr/Reviewed_Request/_where/returns_an_empty_set_if_no_matching_data_was_found.yml +47 -51
  53. data/spec/fixtures/vcr/Reviewed_Request/_where/returns_the_appropriate_page_of_results.yml +105 -207
  54. data/spec/fixtures/vcr/Reviewed_Request/collection_from_response/returns_a_collection_object.yml +138 -195
  55. data/spec/fixtures/vcr/Reviewed_Request/collection_from_response/returns_objects_of_the_correct_class.yml +138 -195
  56. data/spec/fixtures/vcr/Reviewed_Request/object_from_response/returns_an_object_of_the_correct_class.yml +237 -245
  57. data/spec/spec_helper.rb +1 -1
  58. metadata +45 -55
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 204586e11652106dfafc82e5aea75e5d3438a53d
4
+ data.tar.gz: 9e7819e0a1081293bd3e6aa3cc0fc69b1130c59e
5
+ SHA512:
6
+ metadata.gz: 80722e2f6171b5f3b4fef91fe1290a32bb38d2fa70a7b233c23c63bc6d9f49ac483a13d1c29dd4fe35e2ede7b24cdf9537f527fe2f4d13eba3edaf4b4b945576
7
+ data.tar.gz: 343297a543489c280abbf6a8d61d514432fcbb66614f66eac688fb98c4e2bc72852fd14334becd48e9272b7c17070c97953d9772cdc639ee1caaaf33e3cbdcd0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 1.9.3
1
+ 2.0.0-p195
@@ -5,7 +5,6 @@ require 'reviewed/deal'
5
5
 
6
6
  module Reviewed
7
7
  class Article < Base
8
-
9
8
  has_attachments
10
9
 
11
10
  has_many :pages
@@ -1,21 +1,28 @@
1
1
  module Reviewed
2
2
  module Attachable
3
3
 
4
- def attachments tag, opts={}
5
- (@attachments ||= {})[tag] ||= fetch_attachments tag, opts
4
+ def attachments tag=nil, opts={}
5
+ if default_attachments.include?(tag.to_s)
6
+ return attributes['attachments'].select { |x| x.tags.include?(tag.to_s) }
7
+ else
8
+ fetch_attachments(opts.merge!(tags: tag)).to_a
9
+ end
6
10
  end
7
11
 
8
12
  def gallery tags=nil, num=8, page=1
9
- fetch_attachments tags, :gallery => true, :per_page => num, :page => page, :order => 'priority'
13
+ fetch_attachments tags: tags, :gallery => true, :per_page => num, :page => page, :order => 'priority'
10
14
  end
11
15
 
12
16
  private
13
17
 
14
- def fetch_attachments tag, opts={}
15
- params = opts.merge :tags => tag
16
- req = Request.new :resource => Attachment, :scope => self
17
- req.where params
18
+ def default_attachments
19
+ attributes['attachments'] ||= []
20
+ attributes['attachments'].map(&:tags).flatten.uniq.compact
18
21
  end
19
22
 
23
+ def fetch_attachments opts={}
24
+ req = Request.new :resource => Attachment, :scope => self
25
+ req.where opts
26
+ end
20
27
  end
21
28
  end
@@ -2,7 +2,6 @@ require 'reviewed/attachment'
2
2
 
3
3
  module Reviewed
4
4
  class Product < Base
5
-
6
5
  has_attachments
7
6
  has_many :manufacturer_specs
8
7
  has_many :awards
@@ -1,4 +1,4 @@
1
1
  module Reviewed
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.0"
3
3
  API_VERSION = 'v1'
4
4
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Reviewed::Article, vcr: true do
4
+
5
+ let(:client) do
6
+ Reviewed::Client.new(api_key: TEST_KEY, base_uri: TEST_URL)
7
+ end
8
+
9
+ before(:each) do
10
+ @article = client.articles.find('50fb9a81bd0286d55504b952')
11
+ end
12
+
13
+ it 'returns local attachments when available' do
14
+ Reviewed::Request.should_not_receive(:new)
15
+ @article.attachments('hero').first.tags.should eql(['hero'])
16
+ end
17
+
18
+ it 'fetches when a tag is not in pre-loaded set' do
19
+ @article.should_receive(:fetch_attachments).with({tags: 'foobar'})
20
+ @article.attachments('foobar').should eql([])
21
+ end
22
+ end