shopify-mock 0.0.1
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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/README.rdoc +61 -0
- data/Rakefile +1 -0
- data/lib/shopify-mock.rb +37 -0
- data/lib/shopify-mock/fixtures.rb +41 -0
- data/lib/shopify-mock/fixtures/articles.json +30 -0
- data/lib/shopify-mock/fixtures/assets.json +136 -0
- data/lib/shopify-mock/fixtures/blogs.json +15 -0
- data/lib/shopify-mock/fixtures/collect.json +11 -0
- data/lib/shopify-mock/fixtures/comments.json +19 -0
- data/lib/shopify-mock/fixtures/count.json +3 -0
- data/lib/shopify-mock/fixtures/countries.json +16 -0
- data/lib/shopify-mock/fixtures/custom_collections.json +14 -0
- data/lib/shopify-mock/fixtures/customer_groups.json +25 -0
- data/lib/shopify-mock/fixtures/customers.json +32 -0
- data/lib/shopify-mock/fixtures/events.json +13 -0
- data/lib/shopify-mock/fixtures/fulfillments.json +35 -0
- data/lib/shopify-mock/fixtures/images.json +12 -0
- data/lib/shopify-mock/fixtures/metafields.json +14 -0
- data/lib/shopify-mock/fixtures/orders.json +141 -0
- data/lib/shopify-mock/fixtures/pages.json +16 -0
- data/lib/shopify-mock/fixtures/product_search_engines.json +8 -0
- data/lib/shopify-mock/fixtures/products.json +114 -0
- data/lib/shopify-mock/fixtures/provinces.json +100 -0
- data/lib/shopify-mock/fixtures/redirects.json +19 -0
- data/lib/shopify-mock/fixtures/script_tags.json +11 -0
- data/lib/shopify-mock/fixtures/shop.json +26 -0
- data/lib/shopify-mock/fixtures/smart_collections.json +21 -0
- data/lib/shopify-mock/fixtures/test.json +3 -0
- data/lib/shopify-mock/fixtures/themes.json +25 -0
- data/lib/shopify-mock/fixtures/transactions.json +13 -0
- data/lib/shopify-mock/fixtures/variants.json +84 -0
- data/lib/shopify-mock/fixtures/webhooks.json +12 -0
- data/lib/shopify-mock/responses.rb +17 -0
- data/lib/shopify-mock/responses/articles.rb +5 -0
- data/lib/shopify-mock/responses/orders.rb +6 -0
- data/lib/shopify-mock/urls.rb +7 -0
- data/lib/shopify-mock/version.rb +3 -0
- data/shopify-mock.gemspec +28 -0
- data/spec/mockify/fixtures_spec.rb +39 -0
- data/spec/mockify/responses/articles_spec.rb +25 -0
- data/spec/mockify/responses/orders_spec.rb +25 -0
- data/spec/spec_helper.rb +9 -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 +126 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
script: "rspec spec"
|
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= ShopifyMock
|
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 explicitely 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, ShopifyMock is disabled by default, and real-world Internet
|
19
|
+
access is allowed. In a Rails app, ShopifyMock is disabled except for in the :test
|
20
|
+
environment.
|
21
|
+
|
22
|
+
To enable / disable ShopifyMock manually, set ShopifyAPI::Mock.enabled to true or false:
|
23
|
+
|
24
|
+
ShopifyAPI::Mock.enabled = true # or false
|
25
|
+
|
26
|
+
And to completely disable access to the Internet altogether, or re-enable it:
|
27
|
+
|
28
|
+
ShopifyAPI::Mock.allow_internet = false # or true to re-enable
|
29
|
+
|
30
|
+
== Example
|
31
|
+
|
32
|
+
After installing the gem in your Shopify app, load the rails console, and try
|
33
|
+
this quick example:
|
34
|
+
|
35
|
+
rails c
|
36
|
+
:001 > ShopifyAPI::Mock.enabled = true
|
37
|
+
:002 > order = ShopifyAPI::Session("test", "randomtoken") { ShopifyAPI::Order.first }
|
38
|
+
|
39
|
+
You'll notice that the order was not downloaded from Shopify, but based off of
|
40
|
+
a ShopifyMock fixture found in lib/shopify-mock/fixtures/orders.json
|
41
|
+
|
42
|
+
== Fixtures
|
43
|
+
|
44
|
+
You have access to the ShopifyMock fixtures from within your app to help with
|
45
|
+
testing. To access a fixture, use ShopifyAPI::Mock::Fixtures:
|
46
|
+
|
47
|
+
ShopifyAPI::Mock::Fixtures.read(:orders) # => contents of orders.json
|
48
|
+
|
49
|
+
You can also use your own fixtures if you'd like:
|
50
|
+
|
51
|
+
ShopifyAPI::Mock::Fixtures.use :orders, order.to_json # => use custom content for :orders
|
52
|
+
ShopifyAPI::Mock::Fixtures.use :orders, :default # => reset :orders to default fixture
|
53
|
+
ShopifyAPI::Mock::Fixtures.reset # => reset all the fixtures back to their defaults
|
54
|
+
|
55
|
+
Or, if you'd prefer you can point the entire fixture path to a different location:
|
56
|
+
|
57
|
+
ShopifyAPI::Mock::Fixtures.path = File.join(Rails.root, 'spec', 'fixtures')
|
58
|
+
|
59
|
+
|
60
|
+
All of the default fixtures are copied directly from the
|
61
|
+
{Shopify API}[http://api.shopify.com]
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/shopify-mock.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'fakeweb'
|
2
|
+
|
3
|
+
require 'shopify-mock/version'
|
4
|
+
require 'shopify-mock/urls'
|
5
|
+
require 'shopify-mock/fixtures'
|
6
|
+
|
7
|
+
module ShopifyAPI
|
8
|
+
module Mock
|
9
|
+
class << self
|
10
|
+
def enabled
|
11
|
+
@enabled || false
|
12
|
+
end
|
13
|
+
|
14
|
+
def enabled=(value=false)
|
15
|
+
return @enabled if value == @enabled
|
16
|
+
if value
|
17
|
+
load File.expand_path("../shopify-mock/responses.rb", __FILE__)
|
18
|
+
else
|
19
|
+
FakeWeb.clean_registry
|
20
|
+
end
|
21
|
+
@enabled = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def allow_internet
|
25
|
+
@allow_internet || true
|
26
|
+
end
|
27
|
+
|
28
|
+
def allow_internet=(state = true)
|
29
|
+
return @allow_internet if @allow_internet == state
|
30
|
+
@allow_internet = state
|
31
|
+
FakeWeb.allow_net_connect = @allow_internet
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
ShopifyAPI::Mock.enable if defined?(Rails) && Rails.env.test?
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ShopifyAPI
|
2
|
+
module Mock
|
3
|
+
class Fixtures
|
4
|
+
@cache = {}
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def read(name, ext = :json)
|
9
|
+
fixture_name = "#{name.to_s}.#{ext.to_s}"
|
10
|
+
fixture = File.join(self.path, fixture_name)
|
11
|
+
raise "invalid fixture name" unless File.exists? fixture
|
12
|
+
@cache[fixture_name] = File.read(fixture) unless @cache.include? fixture_name
|
13
|
+
@cache[fixture_name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def use(name, content)
|
17
|
+
name = "#{name}.json"
|
18
|
+
if content == :default
|
19
|
+
@cache.delete name if @cache.include? name
|
20
|
+
else
|
21
|
+
@cache[name] = content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
@path ||= File.expand_path("../fixtures/", __FILE__)
|
27
|
+
end
|
28
|
+
|
29
|
+
def path=(value)
|
30
|
+
@path = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def reset
|
34
|
+
@cache = {}
|
35
|
+
@path = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"articles": [
|
3
|
+
{
|
4
|
+
"created_at": "2008-12-31T19:00:00-05:00",
|
5
|
+
"body_html": "I have no idea what to write about, but it's going to rock!",
|
6
|
+
"title": "Some crazy article I'm coming up with",
|
7
|
+
"author": "John",
|
8
|
+
"updated_at": "2009-01-31T19:00:00-05:00",
|
9
|
+
"summary_html": null,
|
10
|
+
"blog_id": 241253187,
|
11
|
+
"tags": "Mystery",
|
12
|
+
"id": 989034056,
|
13
|
+
"user_id": null,
|
14
|
+
"published_at": null
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"created_at": "2008-07-31T20:00:00-04:00",
|
18
|
+
"body_html": "<p>Do <em>you</em> have an <strong>IPod</strong> yet?</p>",
|
19
|
+
"title": "get on the train now",
|
20
|
+
"author": "Dennis",
|
21
|
+
"updated_at": "2008-07-31T20:00:00-04:00",
|
22
|
+
"summary_html": null,
|
23
|
+
"blog_id": 241253187,
|
24
|
+
"tags": "Announcing",
|
25
|
+
"id": 134645308,
|
26
|
+
"user_id": 799407056,
|
27
|
+
"published_at": "2008-07-31T20:00:00-04:00"
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
@@ -0,0 +1,136 @@
|
|
1
|
+
{
|
2
|
+
"assets": [
|
3
|
+
{
|
4
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
5
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
6
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-body-green.gif?1",
|
7
|
+
"key": "assets/bg-body-green.gif"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
11
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
12
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-body-orange.gif?1",
|
13
|
+
"key": "assets/bg-body-orange.gif"
|
14
|
+
},
|
15
|
+
{
|
16
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
17
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
18
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-body-pink.gif?1",
|
19
|
+
"key": "assets/bg-body-pink.gif"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
23
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
24
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-body.gif?1",
|
25
|
+
"key": "assets/bg-body.gif"
|
26
|
+
},
|
27
|
+
{
|
28
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
29
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
30
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-content.gif?1",
|
31
|
+
"key": "assets/bg-content.gif"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
35
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
36
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-footer.gif?1",
|
37
|
+
"key": "assets/bg-footer.gif"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
41
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
42
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-main.gif?1",
|
43
|
+
"key": "assets/bg-main.gif"
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
47
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
48
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/bg-sidebar.gif?1",
|
49
|
+
"key": "assets/bg-sidebar.gif"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
53
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
54
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/shop.css?1",
|
55
|
+
"key": "assets/shop.css"
|
56
|
+
},
|
57
|
+
{
|
58
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
59
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
60
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/shop.css.liquid?1",
|
61
|
+
"key": "assets/shop.css.liquid"
|
62
|
+
},
|
63
|
+
{
|
64
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
65
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
66
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/shop.js?1",
|
67
|
+
"key": "assets/shop.js"
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
71
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
72
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/sidebar-devider.gif?1",
|
73
|
+
"key": "assets/sidebar-devider.gif"
|
74
|
+
},
|
75
|
+
{
|
76
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
77
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
78
|
+
"public_url": "http://static.shopify.com/s/files/1/6909/3384/t/1/assets/sidebar-menu.jpg?1",
|
79
|
+
"key": "assets/sidebar-menu.jpg"
|
80
|
+
},
|
81
|
+
{
|
82
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
83
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
84
|
+
"public_url": null,
|
85
|
+
"key": "config/settings.html"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
89
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
90
|
+
"public_url": null,
|
91
|
+
"key": "layout/theme.liquid"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
95
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
96
|
+
"public_url": null,
|
97
|
+
"key": "templates/article.liquid"
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
101
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
102
|
+
"public_url": null,
|
103
|
+
"key": "templates/blog.liquid"
|
104
|
+
},
|
105
|
+
{
|
106
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
107
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
108
|
+
"public_url": null,
|
109
|
+
"key": "templates/cart.liquid"
|
110
|
+
},
|
111
|
+
{
|
112
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
113
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
114
|
+
"public_url": null,
|
115
|
+
"key": "templates/collection.liquid"
|
116
|
+
},
|
117
|
+
{
|
118
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
119
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
120
|
+
"public_url": null,
|
121
|
+
"key": "templates/index.liquid"
|
122
|
+
},
|
123
|
+
{
|
124
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
125
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
126
|
+
"public_url": null,
|
127
|
+
"key": "templates/page.liquid"
|
128
|
+
},
|
129
|
+
{
|
130
|
+
"created_at": "2010-07-12T15:31:50-04:00",
|
131
|
+
"updated_at": "2010-07-12T15:31:50-04:00",
|
132
|
+
"public_url": null,
|
133
|
+
"key": "templates/product.liquid"
|
134
|
+
}
|
135
|
+
]
|
136
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"blogs": [
|
3
|
+
{
|
4
|
+
"handle": "apple-blog",
|
5
|
+
"created_at": "2011-09-06T11:46:12-04:00",
|
6
|
+
"title": "Mah Blog",
|
7
|
+
"template_suffix": null,
|
8
|
+
"updated_at": "2006-02-01T19:00:00-05:00",
|
9
|
+
"feedburner_location": null,
|
10
|
+
"id": 241253187,
|
11
|
+
"feedburner": null,
|
12
|
+
"commentable": "no"
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"comments": [
|
3
|
+
{
|
4
|
+
"created_at": "2011-09-06T11:46:12-04:00",
|
5
|
+
"body_html": "<p>Hi author, I really <em>like</em> what you're doing there.</p>",
|
6
|
+
"body": "Hi author, I really _like_ what you're doing there.",
|
7
|
+
"author": "Soleone",
|
8
|
+
"updated_at": "2011-09-06T11:46:12-04:00",
|
9
|
+
"blog_id": 241253187,
|
10
|
+
"id": 653537639,
|
11
|
+
"article_id": 134645308,
|
12
|
+
"ip": "127.0.0.1",
|
13
|
+
"user_agent": "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1",
|
14
|
+
"published_at": null,
|
15
|
+
"status": "unapproved",
|
16
|
+
"email": "sole@one.de"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"custom_collections": [
|
3
|
+
{
|
4
|
+
"handle": "ipods",
|
5
|
+
"body_html": "<p>The best selling ipod ever</p>",
|
6
|
+
"title": "IPods",
|
7
|
+
"template_suffix": null,
|
8
|
+
"updated_at": "2008-02-01T19:00:00-05:00",
|
9
|
+
"sort_order": "manual",
|
10
|
+
"id": 841564295,
|
11
|
+
"published_at": "2008-02-01T19:00:00-05:00"
|
12
|
+
}
|
13
|
+
]
|
14
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"customer_groups": [
|
3
|
+
{
|
4
|
+
"name": "Accepts Marketing",
|
5
|
+
"created_at": "2011-08-30T07:46:11-04:00",
|
6
|
+
"updated_at": "2011-08-30T07:46:11-04:00",
|
7
|
+
"id": 789629109,
|
8
|
+
"query": "accepts_marketing:1"
|
9
|
+
},
|
10
|
+
{
|
11
|
+
"name": "Canadian Snowboarders",
|
12
|
+
"created_at": "2011-08-30T07:46:11-04:00",
|
13
|
+
"updated_at": "2011-08-30T07:46:11-04:00",
|
14
|
+
"id": 20610973,
|
15
|
+
"query": "location:Canada"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"name": "Premier Customers",
|
19
|
+
"created_at": "2011-08-30T07:46:11-04:00",
|
20
|
+
"updated_at": "2011-08-30T07:46:11-04:00",
|
21
|
+
"id": 669439218,
|
22
|
+
"query": "John Smith orders_count:>10 total_spent:>100.00"
|
23
|
+
}
|
24
|
+
]
|
25
|
+
}
|