shopify-mock-new 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +121 -0
- data/Rakefile +10 -0
- data/lib/shopify-mock.rb +136 -0
- data/lib/shopify-mock/errors.rb +6 -0
- data/lib/shopify-mock/fixture.rb +124 -0
- data/lib/shopify-mock/fixtures/json/application_charges.json +13 -0
- data/lib/shopify-mock/fixtures/json/articles.json +30 -0
- data/lib/shopify-mock/fixtures/json/assets.json +136 -0
- data/lib/shopify-mock/fixtures/json/blogs.json +15 -0
- data/lib/shopify-mock/fixtures/json/collect.json +11 -0
- data/lib/shopify-mock/fixtures/json/comments.json +19 -0
- data/lib/shopify-mock/fixtures/json/count.json +3 -0
- data/lib/shopify-mock/fixtures/json/countries.json +16 -0
- data/lib/shopify-mock/fixtures/json/custom_collections.json +14 -0
- data/lib/shopify-mock/fixtures/json/customer_groups.json +25 -0
- data/lib/shopify-mock/fixtures/json/customers.json +32 -0
- data/lib/shopify-mock/fixtures/json/events.json +13 -0
- data/lib/shopify-mock/fixtures/json/fulfillments.json +35 -0
- data/lib/shopify-mock/fixtures/json/images.json +12 -0
- data/lib/shopify-mock/fixtures/json/metafields.json +14 -0
- data/lib/shopify-mock/fixtures/json/orders.json +141 -0
- data/lib/shopify-mock/fixtures/json/pages.json +16 -0
- data/lib/shopify-mock/fixtures/json/product_search_engines.json +8 -0
- data/lib/shopify-mock/fixtures/json/products.json +114 -0
- data/lib/shopify-mock/fixtures/json/provinces.json +100 -0
- data/lib/shopify-mock/fixtures/json/recurring_application_charges.json +18 -0
- data/lib/shopify-mock/fixtures/json/redirects.json +19 -0
- data/lib/shopify-mock/fixtures/json/script_tags.json +11 -0
- data/lib/shopify-mock/fixtures/json/shop.json +26 -0
- data/lib/shopify-mock/fixtures/json/smart_collections.json +21 -0
- data/lib/shopify-mock/fixtures/json/themes.json +25 -0
- data/lib/shopify-mock/fixtures/json/transactions.json +13 -0
- data/lib/shopify-mock/fixtures/json/variant.json +23 -0
- data/lib/shopify-mock/fixtures/json/variants.json +88 -0
- data/lib/shopify-mock/fixtures/json/webhooks.json +12 -0
- data/lib/shopify-mock/fixtures/xml/application_charges.xml +12 -0
- data/lib/shopify-mock/fixtures/xml/articles.xml +29 -0
- data/lib/shopify-mock/fixtures/xml/assets.xml +135 -0
- data/lib/shopify-mock/fixtures/xml/blogs.xml +14 -0
- data/lib/shopify-mock/fixtures/xml/collect.xml +10 -0
- data/lib/shopify-mock/fixtures/xml/comments.xml +18 -0
- data/lib/shopify-mock/fixtures/xml/count.xml +2 -0
- data/lib/shopify-mock/fixtures/xml/countries.xml +15 -0
- data/lib/shopify-mock/fixtures/xml/custom_collections.xml +13 -0
- data/lib/shopify-mock/fixtures/xml/customer_groups.xml +24 -0
- data/lib/shopify-mock/fixtures/xml/customers.xml +31 -0
- data/lib/shopify-mock/fixtures/xml/events.xml +12 -0
- data/lib/shopify-mock/fixtures/xml/fulfillments.xml +34 -0
- data/lib/shopify-mock/fixtures/xml/images.xml +11 -0
- data/lib/shopify-mock/fixtures/xml/metafields.xml +13 -0
- data/lib/shopify-mock/fixtures/xml/orders.xml +140 -0
- data/lib/shopify-mock/fixtures/xml/pages.xml +15 -0
- data/lib/shopify-mock/fixtures/xml/product_search_engines.xml +7 -0
- data/lib/shopify-mock/fixtures/xml/products.xml +113 -0
- data/lib/shopify-mock/fixtures/xml/provinces.xml +99 -0
- data/lib/shopify-mock/fixtures/xml/recurring_application_charges.xml +17 -0
- data/lib/shopify-mock/fixtures/xml/redirects.xml +18 -0
- data/lib/shopify-mock/fixtures/xml/script_tags.xml +10 -0
- data/lib/shopify-mock/fixtures/xml/shop.xml +25 -0
- data/lib/shopify-mock/fixtures/xml/smart_collections.xml +20 -0
- data/lib/shopify-mock/fixtures/xml/themes.xml +24 -0
- data/lib/shopify-mock/fixtures/xml/transactions.xml +14 -0
- data/lib/shopify-mock/fixtures/xml/webhooks.xml +11 -0
- data/lib/shopify-mock/response.rb +45 -0
- data/lib/shopify-mock/urls.rb +2 -0
- data/shopify-mock-new.gemspec +31 -0
- data/spec/errors_spec.rb +5 -0
- data/spec/fixture_spec.rb +70 -0
- data/spec/mock_spec.rb +64 -0
- data/spec/response_spec.rb +32 -0
- data/spec/shopify_api_spec.rb +107 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/fixture_support.rb +5 -0
- data/spec/support/http_support.rb +11 -0
- data/spec/support/url_support.rb +8 -0
- metadata +237 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e27b311515d3c1461b6e8f8328816cf9aeb0b404
|
4
|
+
data.tar.gz: a3db30ddbe4063e8206bfced54c4974058cb4d79
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e0b8e163fb5d51c807d9c63434e22739ebdec66fd962af3d53261eadb53bb0cdc7fd50022641d3aace96baa4771eb2c2f2fd12a1637e57f9bec8e50aeac70c6
|
7
|
+
data.tar.gz: 795c0936be8e15905746772f19024c9ecfb36518409e9f26ebcbf20873f6f0759f1b1d94a2f827ff74dac3d8ae99e414cebfd3562d78dbf80800df10bda3b237
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm: 1.9.2
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
= shopify-mock
|
2
|
+
|
3
|
+
This gem is used for testing Shopify apps without having to actually connect to
|
4
|
+
Shopify to develop the application.
|
5
|
+
|
6
|
+
You can use this gem explicitly for testing, or you can also use it in your
|
7
|
+
development environment to speed things up when fiddling around in the web
|
8
|
+
browser, or in the console.
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
|
12
|
+
Add the gem to your Gemfile in the appropriate group:
|
13
|
+
|
14
|
+
gem 'shopify-mock', :group => [:development, :test]
|
15
|
+
|
16
|
+
== Enabling / Disabling
|
17
|
+
|
18
|
+
For non Rails apps, shopify-mock is disabled by default, and real-world Internet
|
19
|
+
access is allowed. In a Rails app, shopify-mock is disabled except for in the :test
|
20
|
+
environment.
|
21
|
+
|
22
|
+
To enable / disable shopify-mock manually, set ShopifyAPI::Mock.enabled to true or false:
|
23
|
+
|
24
|
+
ShopifyAPI::Mock.enabled = true # or false to disable
|
25
|
+
ShopifyAPI::Mock.enabled? # => to get the current state
|
26
|
+
|
27
|
+
And to completely disable access to the Internet altogether, or re-enable it:
|
28
|
+
|
29
|
+
ShopifyAPI::Mock.allow_internet = false # or true to re-enable
|
30
|
+
ShopifyAPI::Mock.allow_internet? # => to get the current state
|
31
|
+
|
32
|
+
== Example
|
33
|
+
|
34
|
+
After installing the gem in your Shopify app, load the rails console, and try
|
35
|
+
this quick example:
|
36
|
+
|
37
|
+
rails c test
|
38
|
+
order = ShopifyAPI::Session.temp("test", "randomtoken") { ShopifyAPI::Order.first }
|
39
|
+
|
40
|
+
You'll notice that the order was not downloaded from Shopify, but based off of
|
41
|
+
a shopify-mock fixture found in lib/shopify-mock/fixtures/orders.json
|
42
|
+
|
43
|
+
== Responses
|
44
|
+
|
45
|
+
You have access to all the registered mock responses through ShopifyAPI::Mock::Response
|
46
|
+
|
47
|
+
ShopifyAPI::Mock::Response.all # => array of all registered responses
|
48
|
+
ShopifyAPI::Mock::Response.clear # => clears all the currently registered responses
|
49
|
+
|
50
|
+
You also have access to each Shopify object asset by it's `id` based on the ids in the fixtures. If you are using the fixtures include in the gem, you can do
|
51
|
+
|
52
|
+
product = ShopifyAPI::Product.find(632910392)
|
53
|
+
|
54
|
+
and you'll get back the fixture product called `Ipod Nano 8GB`
|
55
|
+
|
56
|
+
And you can register your own response:
|
57
|
+
|
58
|
+
ShopifyAPI::Mock::Response.new(:get, "orders/1.xml", "response content")
|
59
|
+
|
60
|
+
== Fixtures
|
61
|
+
|
62
|
+
You have access to the shopify-mock fixtures through ShopifyAPI::Mock::Fixture
|
63
|
+
|
64
|
+
ShopifyAPI::Mock::Fixture.all # => an array of all the fixtures
|
65
|
+
ShopifyAPI::Mock::Fixture.find(:orders, :json) # => returns the orders.json fixture
|
66
|
+
ShopifyAPI::Mock::Fixture.path # => the path to the fixture files
|
67
|
+
|
68
|
+
# to use your own fixture path:
|
69
|
+
ShopifyAPI::Mock::Fixture.path = File.join(Rails.root, 'spec', 'fixtures')
|
70
|
+
ShopifyAPI::Mock.reset # => to reload the fixtures
|
71
|
+
|
72
|
+
A Fixture object has these methods:
|
73
|
+
|
74
|
+
fixture = ShopifyAPI::Mock::Fixture.all.first
|
75
|
+
|
76
|
+
fixture.name # => the name of the fixture, such as :orders
|
77
|
+
fixture.ext # => the extension of the fixture, such as :json, or :xml
|
78
|
+
fixture.data # => the file contents
|
79
|
+
|
80
|
+
# to override the fixture's contents:
|
81
|
+
fixture.data = "new contents" # => use "new contents" for this fixture
|
82
|
+
fixture.data = nil # => resets back to default contents
|
83
|
+
|
84
|
+
== Contributing to shopify-mock
|
85
|
+
|
86
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
87
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
88
|
+
* Fork the project
|
89
|
+
* Start a feature/bugfix branch
|
90
|
+
* Commit and push until you are happy with your contribution
|
91
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
92
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
93
|
+
|
94
|
+
== Resources
|
95
|
+
|
96
|
+
* All of the default fixtures were copied directly from the {Shopify API}[http://api.shopify.com]
|
97
|
+
|
98
|
+
|
99
|
+
== License
|
100
|
+
|
101
|
+
MIT License
|
102
|
+
|
103
|
+
Copyright (c) 2011 Travis Haynes.
|
104
|
+
|
105
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
106
|
+
of this software and associated documentation files (the "Software"), to deal
|
107
|
+
in the Software without restriction, including without limitation the rights
|
108
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
109
|
+
copies of the Software, and to permit persons to whom the Software is
|
110
|
+
furnished to do so, subject to the following conditions:
|
111
|
+
|
112
|
+
The above copyright notice and this permission notice shall be included in
|
113
|
+
all copies or substantial portions of the Software.
|
114
|
+
|
115
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
116
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
117
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
118
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
119
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
120
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
121
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/shopify-mock.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
require 'xml'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'shopify-mock/errors'
|
6
|
+
require 'shopify-mock/urls'
|
7
|
+
require 'shopify-mock/fixture'
|
8
|
+
require 'shopify-mock/response'
|
9
|
+
|
10
|
+
# Mock is an extension for the ShopifyAPI
|
11
|
+
module ShopifyAPI
|
12
|
+
# the main module for managing the Shopify mocks
|
13
|
+
module Mock
|
14
|
+
class << self
|
15
|
+
# get the enabled state of ShopifyAPI::Mock
|
16
|
+
# @return [Boolean] true if enabled
|
17
|
+
# @example Check if ShopifyAPI::Mock is enabled
|
18
|
+
# ShopifyAPI::Mock.enabled # => true or false
|
19
|
+
# @api public
|
20
|
+
def enabled?
|
21
|
+
@enabled || false
|
22
|
+
end
|
23
|
+
|
24
|
+
# enable or disable ShopifyAPI::Mock
|
25
|
+
# @param [Boolean] value true to enable ShopifyAPI::Mock, false to disable
|
26
|
+
# @return [Boolean] true if enabled
|
27
|
+
# @example Enabling ShopifyAPI::Mock
|
28
|
+
# ShopifyAPI::Mock.enabled = true
|
29
|
+
# @api public
|
30
|
+
def enabled=(value=false)
|
31
|
+
return @enabled if value == @enabled
|
32
|
+
if value
|
33
|
+
#load File.expand_path("../shopify-mock/responses.rb", __FILE__)
|
34
|
+
ShopifyAPI::Mock.register_fixed_responses
|
35
|
+
else
|
36
|
+
ShopifyAPI::Mock::Response.clear
|
37
|
+
end
|
38
|
+
@enabled = value
|
39
|
+
end
|
40
|
+
|
41
|
+
# resets the ShopifyAPI::Mocks back to their original state
|
42
|
+
# @return [Boolean] true when successful
|
43
|
+
# @example Reset the mocks
|
44
|
+
# ShopifyAPI::Mock.reset
|
45
|
+
# @raise [ShopifyAPI::Mock::DisabledError] Raised when trying to reset the mocks when they are disabled
|
46
|
+
# @api public
|
47
|
+
def reset
|
48
|
+
raise ShopifyAPI::Mock::DisabledError, "cannot reset ShopifyAPI::Mock while it is disabled" \
|
49
|
+
unless ShopifyAPI::Mock.enabled?
|
50
|
+
ShopifyAPI::Mock.enabled = false
|
51
|
+
ShopifyAPI::Mock.enabled = true
|
52
|
+
end
|
53
|
+
|
54
|
+
# gets the state of access to the real Internet
|
55
|
+
# @return [Boolean] false if all access to the Internet has been disabled
|
56
|
+
# @example Check if access has been disabled
|
57
|
+
# can_access_internet = Shopify::Mock.allow_internet
|
58
|
+
# @api public
|
59
|
+
def allow_internet?
|
60
|
+
@allow_internet || true
|
61
|
+
end
|
62
|
+
|
63
|
+
# enables or disables access to the real Internet
|
64
|
+
# @return [Boolean] status of real Internet access
|
65
|
+
# @example Turn off access to the Internet altogether
|
66
|
+
# Shopify::Mock.allow_internet = false
|
67
|
+
# @api public
|
68
|
+
def allow_internet=(state = true)
|
69
|
+
return @allow_internet if @allow_internet == state
|
70
|
+
@allow_internet = state
|
71
|
+
FakeWeb.allow_net_connect = @allow_internet
|
72
|
+
end
|
73
|
+
|
74
|
+
# registers all the fixed responses
|
75
|
+
# @return [Array] the responses that were registered
|
76
|
+
# @api private
|
77
|
+
def register_fixed_responses
|
78
|
+
ShopifyAPI::Mock::Response.clear
|
79
|
+
|
80
|
+
registered_responses = []
|
81
|
+
ShopifyAPI::Mock::Fixture.all.each do |fixture|
|
82
|
+
# register the count fixture for this resource, if it exists
|
83
|
+
count_fixture = ShopifyAPI::Mock::Fixture.find(:count, fixture.ext.to_sym)
|
84
|
+
registered_responses << ShopifyAPI::Mock::Response.new(
|
85
|
+
:get, "#{fixture.name.to_s}/count.#{fixture.ext}",
|
86
|
+
count_fixture.data
|
87
|
+
) unless count_fixture.nil?
|
88
|
+
# register the resource fixture
|
89
|
+
registered_responses << ShopifyAPI::Mock::Response.new(
|
90
|
+
:get, "#{fixture.name.to_s}.#{fixture.ext.to_s}",
|
91
|
+
fixture.data
|
92
|
+
)
|
93
|
+
# register the individual get by id
|
94
|
+
# /products/:id.:format
|
95
|
+
#TODO : add xml responses as well
|
96
|
+
fixture_data = parse_fixture_data(fixture)
|
97
|
+
if fixture.ext == :json
|
98
|
+
objects = fixture_data[fixture.name.to_s]
|
99
|
+
if objects && objects.is_a?(Array)
|
100
|
+
objects.each do |obj|
|
101
|
+
if obj.has_key? 'id'
|
102
|
+
result = { "#{fixture.name.to_s.singularize}" => obj }
|
103
|
+
registered_responses << ShopifyAPI::Mock::Response.new(:get, "#{fixture.name.to_s}/#{obj['id']}.#{fixture.ext.to_s}", result.to_json)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
elsif fixture.ext == :xml
|
108
|
+
objects = fixture_data.find("//#{fixture.name.to_s}/#{fixture.name.to_s.singularize}")
|
109
|
+
if objects
|
110
|
+
objects.each do |obj|
|
111
|
+
id_node = obj.find_first('id')
|
112
|
+
if id_node && id_node.content
|
113
|
+
_id = id_node.content
|
114
|
+
registered_responses << ShopifyAPI::Mock::Response.new(:get, "#{fixture.name.to_s}/#{_id}.#{fixture.ext.to_s}", obj.to_s)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
def parse_fixture_data(fixture)
|
124
|
+
case fixture.ext
|
125
|
+
when :xml
|
126
|
+
XML::Document.string(fixture.data)
|
127
|
+
when :json
|
128
|
+
JSON.parse(fixture.data)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# enable mocking in Rails test environments by default
|
136
|
+
ShopifyAPI::Mock.enabled = defined?(Rails) && Rails.env.test?
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module ShopifyAPI
|
2
|
+
module Mock
|
3
|
+
|
4
|
+
# provides easy access to fixtures
|
5
|
+
class Fixture
|
6
|
+
@@path = nil
|
7
|
+
@@cache = {}
|
8
|
+
|
9
|
+
# creates a new instance of ShopifyAPI::Mock::Fixture
|
10
|
+
# @param [String] file_name The location of the file to load into the fixture
|
11
|
+
# @raise [IOError] Raised when file_name is invalid
|
12
|
+
# @api private
|
13
|
+
def initialize(file_name)
|
14
|
+
raise IOError, "File not found: #{file_name}" unless File.exists? file_name
|
15
|
+
@file_name = file_name
|
16
|
+
end
|
17
|
+
|
18
|
+
# gets the content of the fixture
|
19
|
+
# @return [String] the contents of the file, or @data if it was overwritten
|
20
|
+
# @example Create a fixture and read its contents
|
21
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
22
|
+
# data = fixture.data # => the contents of "./orders.xml"
|
23
|
+
# @api public
|
24
|
+
def data
|
25
|
+
@data || File.read(@file_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
# gets the name of the fixture
|
29
|
+
# @return [Symbol] the the file name without the extension
|
30
|
+
# @example Load a fixture and get its name
|
31
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
32
|
+
# name = fixture.name # => :orders
|
33
|
+
# @api public
|
34
|
+
def name
|
35
|
+
File.basename(@file_name, ".#{self.ext.to_s}").to_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
# overrides the contents of the fixture
|
39
|
+
# @param [String] value The new value to use, or set to nil to reset to default
|
40
|
+
# @return The new contents of the fixture
|
41
|
+
# @example Override a the contents of a fixture
|
42
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
43
|
+
# data = fixture.data # => the contents of "./orders.xml"
|
44
|
+
# fixture.data = "hello world"
|
45
|
+
# data = fixture.data # => "hello world"
|
46
|
+
# @example Set contents of a fixture back to their default
|
47
|
+
# fixture.data = nil
|
48
|
+
# @api public
|
49
|
+
def data=(value)
|
50
|
+
@data = value
|
51
|
+
data
|
52
|
+
end
|
53
|
+
|
54
|
+
# gets the extension of the fixture
|
55
|
+
# @return [Symbol] The extension
|
56
|
+
# @example Create a new fixture and get its extension
|
57
|
+
# fixture = ShopifyAPI::Fixture.new "./orders.xml"
|
58
|
+
# ext = fixture.ext # => :xml
|
59
|
+
# @api public
|
60
|
+
def ext
|
61
|
+
File.extname(@file_name).gsub(".","").to_sym
|
62
|
+
end
|
63
|
+
|
64
|
+
class << self
|
65
|
+
# finds all the fixtures
|
66
|
+
# @return [Array, Fixture] an array of all the Fixtures
|
67
|
+
# @example Find all the fixtures
|
68
|
+
# ShopifyAPI::Mock::Fixture.all
|
69
|
+
# @api public
|
70
|
+
def all
|
71
|
+
# get a list of all the fixture files
|
72
|
+
files = []
|
73
|
+
Dir[File.join(ShopifyAPI::Mock::Fixture.path, "**", "*")].each do |f|
|
74
|
+
files << f unless File.directory? f
|
75
|
+
end
|
76
|
+
|
77
|
+
# map files to fixtures
|
78
|
+
files.map do |file_name|
|
79
|
+
fixture_name = File.basename(file_name)
|
80
|
+
@@cache[fixture_name] ||= Fixture.new(file_name)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# finds a fixture by name
|
85
|
+
# @param [Symbol] name The name of the fixture
|
86
|
+
# @param [Symbol] ext The extension of the symbol - defaults to :json
|
87
|
+
# @return [ShopifyAPI::Mock::Fixture] The fixture or nil if not found
|
88
|
+
# @example Find the orders json fixture
|
89
|
+
# fixture = ShopifyAPI::Mock::Fixture.find :orders
|
90
|
+
# @example Find the orders xml fixture
|
91
|
+
# fixture = ShopifyAPI::Mock::Fixture.find :orders, :xml
|
92
|
+
# @api public
|
93
|
+
def find(name, ext = :json)
|
94
|
+
fixture_name = "#{name.to_s}.#{ext.to_s}"
|
95
|
+
file_name = File.join(self.path, ext.to_s, fixture_name)
|
96
|
+
return nil unless File.exists? file_name
|
97
|
+
@@cache[fixture_name] ||= Fixture.new(file_name)
|
98
|
+
end
|
99
|
+
|
100
|
+
# gets the current path to the fixtures
|
101
|
+
# @return [String] The fixtures path
|
102
|
+
# @example Get the fixtures path
|
103
|
+
# fixture_path = ShopifyAPI::Mock::Fixture.path
|
104
|
+
# @api public
|
105
|
+
def path
|
106
|
+
@@path ||= File.expand_path("../fixtures/", __FILE__)
|
107
|
+
end
|
108
|
+
|
109
|
+
# sets the current fixtures path
|
110
|
+
# @param [String] value The new fixtures path
|
111
|
+
# @return [String] The new fixtures path
|
112
|
+
# @example Override the default fixtures path
|
113
|
+
# ShopifyAPI::Mock::Fixture.path = File.join(Rails.root, "spec", "fixtures", "shopify")
|
114
|
+
# @api public
|
115
|
+
def path=(value)
|
116
|
+
return @@path if @@path == value
|
117
|
+
@@path = value
|
118
|
+
@@cache = {}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"application_charge": {
|
3
|
+
"price": "100.00",
|
4
|
+
"name": "Super Duper Expensive action",
|
5
|
+
"created_at": "2011-09-06T11:46:15-04:00",
|
6
|
+
"return_url": "http://super-duper.shopifyapps.com?charge_id=1007331646",
|
7
|
+
"updated_at": "2011-09-06T11:46:15-04:00",
|
8
|
+
"confirmation_url": "http://apple.myshopify.com/admin/subscriptions/confirm_application_charge/1007331646?signature=BAhpBD6pCjw%3D--ce8f74151dcf7c56ebbf2a15f7a2694533b46fd4",
|
9
|
+
"id": 1007331646,
|
10
|
+
"test": null,
|
11
|
+
"status": "pending"
|
12
|
+
}
|
13
|
+
}
|