Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed double root bug with ActiveSupport 3.2.0 #16

Merged
merged 3 commits into from

3 participants

lib/shopify_api/json_format.rb
@@ -21,3 +21,19 @@ def decode(json)
end
end
end
+
+module ActiveModel
+ module Serializers
+ module JSON
+ def as_json(options = nil)
+ root = options[:root] if options.try(:key?, :root)
@jduff Owner
jduff added a note

Your tabbing is a bit messed up here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jduff
Owner

Does everything still work under ActiveResource 3.0 and 3.1?

@dennisfoconnor

Yes, everything still works under 3.0 and 3.1

Dennis O'Connor Fixed tabbing cf6c427
@odorcicd odorcicd commented on the diff
test/detailed_log_subscriber_test.rb
@@ -27,7 +27,7 @@ def set_logger(logger)
assert_equal "GET http://localhost:80/admin/pages/1.json", @logger.logged(:info)[0]
assert_match /\-\-\> 200/, @logger.logged(:info)[1]
assert_equal "Headers: {\"Accept\"=>\"application/json\"}", @logger.logged(:info)[2]
- assert_equal "Response:\n{\"page\":{\"title\":\"Shopify API\",\"id\":1}}", @logger.logged(:info)[3]
@odorcicd Collaborator
odorcicd added a note

We'll need to continue to support 1.8.7 and having the tests run, can you get them to pass on both? Where there are ordering issues, parse the json and compare the objects I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dennisfoconnor

@jduff @odorcicd Updated with changes.

@odorcicd
Collaborator

:ok:

@jduff
Owner

:+1:

@dennisfoconnor dennisfoconnor merged commit 6787773 into Shopify:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 27, 2012
  1. Fixed double root bug with ActiveSupport 3.2.0

    Dennis O'Connor authored
Commits on Jan 31, 2012
  1. Fixed tabbing

    Dennis O'Connor authored
Commits on Feb 6, 2012
  1. Fixed failing tests on ruby 1.8.7

    Dennis O'Connor authored
This page is out of date. Refresh to see the latest.
View
18 lib/shopify_api/json_format.rb
@@ -3,7 +3,7 @@ class Base
def encode(options = {})
same = dup
same.attributes = {self.class.element_name => same.attributes} if self.class.format.extension == 'json'
-
+
same.send("to_#{self.class.format.extension}", options)
end
end
@@ -21,3 +21,19 @@ def decode(json)
end
end
end
+
+module ActiveModel
+ module Serializers
+ module JSON
+ def as_json(options = nil)
+ root = options[:root] if options.try(:key?, :root)
+ if include_root_in_json
+ root = self.class.model_name.element if root == true
+ { root => serializable_hash(options) }
+ else
+ serializable_hash(options)
+ end
+ end
+ end
+ end
+end
View
8 test/blog_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+class BlogTest < Test::Unit::TestCase
+ test "blog creation" do
+ fake "blogs", :method => :post, :status => 202
+ ShopifyAPI::Blog.create(:title => "Test Blog")
+ assert_equal '{"blog":{"title":"Test Blog"}}', FakeWeb.last_request.body
+ end
+end
View
3  test/detailed_log_subscriber_test.rb
@@ -27,7 +27,8 @@ def set_logger(logger)
assert_equal "GET http://localhost:80/admin/pages/1.json", @logger.logged(:info)[0]
assert_match /\-\-\> 200/, @logger.logged(:info)[1]
assert_equal "Headers: {\"Accept\"=>\"application/json\"}", @logger.logged(:info)[2]
- assert_equal "Response:\n{\"page\":{\"title\":\"Shopify API\",\"id\":1}}", @logger.logged(:info)[3]
@odorcicd Collaborator
odorcicd added a note

We'll need to continue to support 1.8.7 and having the tests run, can you get them to pass on both? Where there are ordering issues, parse the json and compare the objects I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ assert_match /Response:\n\{\"page\"\:\{((\"id\"\:1)|(\"title\"\:\"Shopify API\")),((\"id\"\:1)|(\"title\"\:\"Shopify API\"))\}\}/, @logger.logged(:info)[3]
+
end
test "logging on #find with an error" do
View
13 test/fixtures/blogs.json
@@ -0,0 +1,13 @@
+{
+ "blog": {
+ "handle": "test-blog",
+ "created_at": "2012-01-10T17:45:19-05:00",
+ "title": "Test Blog",
+ "template_suffix": null,
+ "updated_at": "2012-01-10T17:45:19-05:00",
+ "feedburner_location": null,
+ "id": 1008414260,
+ "feedburner": null,
+ "commentable": "no"
+ }
+}
View
2  test/product_test.rb
@@ -12,7 +12,7 @@ def test_add_metafields_to_product
fake "products/632910392/metafields", :method => :post, :status => 201, :body => load_fixture('metafield')
field = @product.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
-
+ assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(FakeWeb.last_request.body)
assert !field.new_record?
assert_equal "contact", field.namespace
assert_equal "email", field.key
View
2  test/shop_test.rb
@@ -29,7 +29,7 @@ def test_add_metafield
fake "metafields", :method => :post, :status => 201, :body =>load_fixture('metafield')
field = @shop.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
-
+ assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(FakeWeb.last_request.body)
assert !field.new_record?
assert_equal "contact", field.namespace
assert_equal "email", field.key
Something went wrong with that request. Please try again.