forked from Shopify/shopify_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_generator_test.rb
113 lines (95 loc) · 3.48 KB
/
install_generator_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'test_helper'
require 'generators/shopify_app/install/install_generator'
class InstallGeneratorTest < Rails::Generators::TestCase
tests ShopifyApp::Generators::InstallGenerator
destination File.expand_path("../tmp", File.dirname(__FILE__))
setup do
prepare_destination
provide_existing_application_file
provide_existing_routes_file
provide_existing_application_controller
end
test "creates the ShopifyApp initializer" do
run_generator
assert_file "config/initializers/shopify_app.rb" do |shopify_app|
assert_match 'config.api_key = "<api_key>"', shopify_app
assert_match 'config.secret = "<secret>"', shopify_app
assert_match 'config.scope = "read_orders, read_products"', shopify_app
assert_match "config.embedded_app = true", shopify_app
end
end
test "creates the ShopifyApp initializer for non embedded app" do
stub_embedded_false
run_generator
assert_file "config/initializers/shopify_app.rb" do |shopify_app|
assert_match "config.embedded_app = false", shopify_app
end
end
test "creats and injects into omniauth initializer" do
run_generator
assert_file "config/initializers/omniauth.rb" do |omniauth|
assert_match "provider :shopify", omniauth
end
end
test "creates the default shopify_session_repository" do
run_generator
assert_file "config/initializers/shopify_session_repository.rb" do |file|
assert_match "ShopifyApp::SessionRepository.storage = InMemorySessionStore", file
end
end
test "adds the embedded app options to application.rb" do
run_generator
assert_file "config/application.rb" do |application|
assert_match "config.action_dispatch.default_headers.delete('X-Frame-Options')", application
assert_match "config.action_dispatch.default_headers['P3P'] = 'CP=\"Not used\"'", application
end
end
test "doesn't add embedd options if -embedded false" do
stub_embedded_false
run_generator
assert_file "config/application.rb" do |application|
refute_match "config.action_dispatch.default_headers.delete('X-Frame-Options')", application
refute_match "config.action_dispatch.default_headers['P3P'] = 'CP=\"Not used\"'", application
end
end
test "injects into application controller" do
run_generator
assert_file "app/controllers/application_controller.rb" do |controller|
assert_match " include ShopifyApp::Controller\n", controller
end
end
test "creates the embedded_app layout" do
run_generator
assert_file "app/views/layouts/embedded_app.html.erb"
end
test "creates the home controller" do
run_generator
assert_file "app/controllers/home_controller.rb"
end
test "creates the home index view with embedded options" do
run_generator
assert_file "app/views/home/index.html.erb" do |index|
assert_match "ShopifyApp.ready", index
end
end
test "creates the home index view with embedded false" do
stub_embedded_false
run_generator
assert_file "app/views/home/index.html.erb" do |index|
refute_match "ShopifyApp.ready", index
end
end
test "adds engine and home route to routes" do
run_generator
assert_file "config/routes.rb" do |routes|
assert_match "mount ShopifyApp::Engine, at: '/'", routes
assert_match "root :to => 'home#index'", routes
end
end
private
def stub_embedded_false
ShopifyApp::Generators::InstallGenerator.any_instance.stubs(:opts).returns(
{embedded: 'false'}
)
end
end