ember-appkit-rails 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/templates/application.hbs +4 -4
  3. data/lib/ember/appkit/rails.rb +1 -0
  4. data/lib/ember/appkit/rails/engine.rb +6 -3
  5. data/lib/ember/appkit/rails/sprockets/context.rb +1 -1
  6. data/lib/ember/appkit/rails/version.rb +1 -1
  7. data/lib/ember/appkit/rails/walker.rb +86 -57
  8. data/lib/generators/ember/bootstrap_generator.rb +14 -6
  9. data/lib/generators/ember/scaffold_controller_override.rb +3 -3
  10. data/lib/generators/ember/scaffold_override.rb +1 -1
  11. data/lib/generators/templates/adapter.js.erb +1 -1
  12. data/lib/generators/templates/application.js.erb +1 -1
  13. data/lib/generators/templates/environment.js.erb +19 -0
  14. data/lib/generators/templates/environments/development.js.erb +9 -0
  15. data/lib/generators/templates/environments/production.js.erb +14 -0
  16. data/{test/dummy/config/environments/development.js → lib/generators/templates/environments/test.js.erb} +2 -0
  17. data/lib/generators/templates/router.js.es6 +9 -1
  18. data/lib/generators/templates/scaffold/route/edit.js.es6 +2 -4
  19. data/lib/generators/templates/scaffold/route/new.js.es6 +1 -2
  20. data/lib/generators/templates/scaffold/route/show.js.es6 +1 -2
  21. data/lib/generators/templates/scaffold/template/form.hbs +2 -2
  22. data/lib/generators/templates/scaffold/template/show.hbs +1 -1
  23. data/lib/generators/templates/scaffold_controller/controller.rb +5 -4
  24. data/test/dummy/Gemfile +1 -1
  25. data/test/dummy/config/{adapter.js.erb → adapters/application.js.es6.erb} +1 -1
  26. data/test/dummy/config/application.js +1 -1
  27. data/test/dummy/config/environment.js.erb +19 -0
  28. data/test/dummy/config/environments/development.js.erb +9 -0
  29. data/test/dummy/config/environments/production.js.erb +14 -0
  30. data/{lib/generators/templates/environments/development.js → test/dummy/config/environments/test.js.erb} +2 -0
  31. data/test/dummy/config/initializers/secret_token.rb +1 -1
  32. data/test/dummy/config/router.js.es6 +9 -1
  33. data/test/dummy/config/routes.rb +3 -0
  34. data/test/dummy/log/test.log +35 -7
  35. data/test/dummy/tmp/cache/assets/test/sprockets/10fe949cc641775f5630b5dad6deb5fc +0 -0
  36. data/test/dummy/tmp/cache/assets/test/sprockets/129b422236f443119233cdb0a4525a06 +0 -0
  37. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  38. data/test/dummy/tmp/cache/assets/test/sprockets/1f15c49a05b13c3a7ee50d2ac3900f38 +0 -0
  39. data/test/dummy/tmp/cache/assets/test/sprockets/25b8b60341168a02f48dabd2b0aa82ad +0 -0
  40. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  41. data/test/dummy/tmp/cache/assets/test/sprockets/4a1d4e32cd7b9fd1c62bfd553ae56051 +0 -0
  42. data/test/dummy/tmp/cache/assets/test/sprockets/660bc633c8899c6c1b20514637fa0169 +0 -0
  43. data/test/dummy/tmp/cache/assets/test/sprockets/67afcba9807cd5e57b80b5fdf9f26758 +0 -0
  44. data/test/dummy/tmp/cache/assets/test/sprockets/7ca4966e0a480430a858a7ab74518c75 +0 -0
  45. data/test/dummy/tmp/cache/assets/test/sprockets/827fafc13575b345cc572fd041ef1fba +0 -0
  46. data/test/dummy/tmp/cache/assets/test/sprockets/{07afa5d8ceda557642e2330ab45eb203 → 83030d43d9bff738a1a01366d61d7691} +0 -0
  47. data/test/dummy/tmp/cache/assets/test/sprockets/83a9a7d15d681a382363d2bccb9528bb +0 -0
  48. data/test/dummy/tmp/cache/assets/test/sprockets/83af35bb6b852de883a26a9458fd4e3a +0 -0
  49. data/test/dummy/tmp/cache/assets/test/sprockets/{ae884a1acda0e6f9bb27a856a22bb08d → 8adfb5e646dca2c629e5d3dc88e2c2e9} +0 -0
  50. data/test/dummy/tmp/cache/assets/test/sprockets/9160f792acb62d1f7721c714681fcfe6 +0 -0
  51. data/test/dummy/tmp/cache/assets/test/sprockets/a6a0d79927cb0ec286aa0afb9812685c +0 -0
  52. data/test/dummy/tmp/cache/assets/test/sprockets/bb4a2293175928af3e23c47488077098 +0 -0
  53. data/test/dummy/tmp/cache/assets/test/sprockets/bf689240392e7355c0de5cfd47272146 +0 -0
  54. data/test/dummy/tmp/cache/assets/test/sprockets/cdbe9110f011148cc7a1f172dc18a883 +0 -0
  55. data/test/dummy/tmp/cache/assets/test/sprockets/d5a48c6656341c56cac8a8e42bb925a5 +0 -0
  56. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  57. data/test/dummy/tmp/cache/assets/test/sprockets/de0932670a6c856bc6eda1586fd29061 +0 -0
  58. data/test/dummy/tmp/cache/assets/test/sprockets/de94a60b438eb5bf57653f3a220acd80 +0 -0
  59. data/test/dummy/tmp/cache/assets/test/sprockets/e9abb671d48f6ff2be6ffb463ea652bf +0 -0
  60. data/test/dummy/tmp/cache/assets/test/sprockets/eeb5bd38d1dad0d908461fd114f702bc +0 -0
  61. data/test/fixtures/routes_with_api_version_namespaces_and_route.rb +12 -0
  62. data/test/fixtures/walker.rb +76 -0
  63. data/test/generators/bootstrap_generator_test.rb +14 -6
  64. data/test/generators/resource_override_test.rb +0 -9
  65. data/test/generators/scaffold_override_test.rb +22 -9
  66. data/test/integration/engine_test.rb +34 -0
  67. data/test/support/generator_test_support.rb +11 -0
  68. data/vendor/assets/javascripts/app.js.es6.erb +1 -16
  69. data/vendor/assets/javascripts/ember-appkit/index.js +1 -0
  70. data/vendor/assets/javascripts/ember-appkit/resolver.js +12 -7
  71. data/vendor/assets/javascripts/ember-appkit/resolver_ext.js +40 -0
  72. metadata +55 -44
  73. data/lib/generators/templates/environment.js +0 -12
  74. data/lib/generators/templates/environments/production.js +0 -3
  75. data/lib/generators/templates/environments/test.js +0 -3
  76. data/test/dummy/config/environment.js +0 -12
  77. data/test/dummy/config/environments/production.js +0 -3
  78. data/test/dummy/config/environments/test.js +0 -3
  79. data/test/dummy/tmp/cache/assets/test/sprockets/e15ec26dd7914851e352c6f2c73c4284 +0 -0
  80. data/test/dummy/tmp/cache/assets/test/sprockets/e3ddb4a07e99c5bbf5f9cd9db3cdb82a +0 -0
  81. data/test/dummy/tmp/cache/assets/test/sprockets/fde9e78f8d55a70f4ef757638fc6cde0 +0 -0
  82. data/test/dummy/tmp/cache/assets/test/sprockets/fdfac6623944c5a23737724cbd90e58e +0 -0
@@ -5,5 +5,5 @@
5
5
  </div>
6
6
  <% end -%>
7
7
 
8
- <button type="submit" {{action save}}>Save</button>
9
- <button type="submit" {{action cancel}}>Cancel</button>
8
+ <button type="submit" {{action save this}}>Save</button>
9
+ <button type="submit" {{action cancel this}}>Cancel</button>
@@ -1,6 +1,6 @@
1
1
  <h3>{{id}}</h3>
2
2
 
3
- <p>{{link-to 'Edit' '<%= file_name.pluralize -%>.edit' this}} <button {{action destroyRecord}}>Destroy</button></p>
3
+ <p>{{link-to 'Edit' '<%= file_name.pluralize -%>.edit' this}} <button {{action destroyRecord this}}>Destroy</button></p>
4
4
 
5
5
  <ul>
6
6
  <% attributes.each do |attribute| -%>
@@ -1,15 +1,16 @@
1
1
  <% api_version = Rails.application.config.ember.api_version -%>
2
2
  class Api::V<%= api_version %>::<%= controller_class_name %>Controller < ApplicationController
3
3
  before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
4
+ respond_to :json
4
5
 
5
6
  # GET <%= route_url %>
6
7
  def index
7
- render json: <%= orm_class.all(class_name) %>
8
+ respond_with <%= orm_class.all(class_name) %>
8
9
  end
9
10
 
10
11
  # GET <%= route_url %>/1
11
12
  def show
12
- render json: <%= "@#{singular_table_name}" %>
13
+ respond_with <%= "@#{singular_table_name}" %>
13
14
  end
14
15
 
15
16
  # POST <%= route_url %>
@@ -17,7 +18,7 @@ class Api::V<%= api_version %>::<%= controller_class_name %>Controller < Applica
17
18
  @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
18
19
 
19
20
  if @<%= orm_instance.save %>
20
- render json: <%= "@#{singular_table_name}" %>, status: :created, location: [:api, :v<%= api_version %>, <%= "@#{singular_table_name}" %>]
21
+ respond_with <%= "@#{singular_table_name}" %>, status: :created, location: [:api, :v<%= api_version %>, <%= "@#{singular_table_name}" %>]
21
22
  else
22
23
  render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
23
24
  end
@@ -26,7 +27,7 @@ class Api::V<%= api_version %>::<%= controller_class_name %>Controller < Applica
26
27
  # PATCH/PUT <%= route_url %>/1
27
28
  def update
28
29
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
29
- render json: <%= "@#{singular_table_name}" %>, status: :ok, location: [:api, :v<%= api_version %>, <%= "@#{singular_table_name}" %>]
30
+ respond_with <%= "@#{singular_table_name}" %>, status: :ok, location: [:api, :v<%= api_version %>, <%= "@#{singular_table_name}" %>]
30
31
  else
31
32
  render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
32
33
  end
@@ -1,7 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4
- gem 'rails', '4.0.1'
4
+ gem 'rails', '4.0.2'
5
5
 
6
6
 
7
7
  # Use SCSS for stylesheets
@@ -1,3 +1,3 @@
1
- window.App.ApplicationAdapter = DS.ActiveModelAdapter.extend({
1
+ export default DS.ActiveModelAdapter.extend({
2
2
  namespace: 'api/v<%= Rails.application.config.ember.api_version %>'
3
3
  });
@@ -2,7 +2,7 @@
2
2
  //= require environment
3
3
  //= require ember-appkit
4
4
  //= require_self
5
- //= require adapter
5
+ //= require_tree ./adapters
6
6
  //= require router
7
7
  //= require_tree ../app
8
8
  //= require_tree ./initializers
@@ -0,0 +1,19 @@
1
+ //= require_self
2
+ //= require_environment_from ./environments
3
+ /*
4
+ This is useful when using canary versions of Ember to enable
5
+ feature flags before Ember itself is loaded.
6
+
7
+ See the feature flags guide for details:
8
+
9
+ http://emberjs.com/guides/configuring-ember/feature-flags/
10
+ */
11
+
12
+ window.config = {};
13
+
14
+ <% config = Rails.application.config.ember %>
15
+
16
+ config.modulePrefix = '<%= config.namespaces.app %>';
17
+ config.routerPrefix = '<%= config.namespaces.config %>';
18
+ config.adapterPrefix = '<%= config.namespaces.config %>';
19
+ config.serializerPrefix = '<%= config.namespaces.config %>';
@@ -0,0 +1,9 @@
1
+ //= require handlebars
2
+ //= require ember
3
+ //= require ember-data
4
+
5
+ config.LOG_ACTIVE_GENERATION = true
6
+ config.LOG_MODULE_RESOLVER = true
7
+ config.LOG_TRANSITIONS = true
8
+ config.LOG_TRANSITIONS_INTERNAL = true
9
+ config.LOG_VIEW_LOOKUPS = true
@@ -0,0 +1,14 @@
1
+ //= require handlebars.runtime
2
+ //= require ember.prod
3
+ //= require ember-data.prod
4
+
5
+ // For some configuration settings such as API keys,
6
+ // you should read them from the environment rather
7
+ // than checking them into version control. See also
8
+ // the Figaro gem.
9
+ // Keep in mind that API keys in js are visible to
10
+ // someone poking in the browser, so never expose
11
+ // a truly private API key in javascript.
12
+ // my_api_key = <%= ENV['MY_API_KEY'] %>
13
+
14
+ Ember.LOG_VERSION = false
@@ -1,3 +1,5 @@
1
1
  //= require handlebars
2
2
  //= require ember
3
3
  //= require ember-data
4
+
5
+ Ember.LOG_VERSION = false
@@ -9,4 +9,4 @@
9
9
 
10
10
  # Make sure your secret_key_base is kept private
11
11
  # if you're sharing your code publicly.
12
- Dummy::Application.config.secret_key_base = '98d2b076984423a47e4eeb592556c70d6f011cbd95e7df244fda23040f1f5afd00655bb3cd8400392e08b7c16ce663e155493257ca891c1d0569d001afa64f0e'
12
+ Dummy::Application.config.secret_key_base = 'd20399e714b77996a5e66f97d4b2ab403a360272f5e17b7e6a7672745e00601faac711f88db3b0d0297ecf9986526068388b4ee6e9fe3017c2f442a0bb75721b'
@@ -1,4 +1,12 @@
1
- var Router = Ember.Router.extend();
1
+ var Router = Ember.Router.extend({
2
+ // Uncomment to change Ember's router to use the
3
+ // HTML5 History API
4
+ // Please note that not all browsers support this!
5
+ // You will also need to uncomment the greedy route matcher
6
+ // in config/routes.rb
7
+
8
+ // location: 'history'
9
+ });
2
10
 
3
11
  Router.map(function() {
4
12
  });
@@ -53,4 +53,7 @@ Dummy::Application.routes.draw do
53
53
  # # (app/controllers/admin/products_controller.rb)
54
54
  # resources :products
55
55
  # end
56
+
57
+ # Uncomment when using 'history' as the location in Ember's router
58
+ # get '*foo', :to => 'landing#index'
56
59
  end
@@ -1,3 +1,6 @@
1
+ -----------------------------------------------------------------------------------
2
+ BootstrapGeneratorTest: test_Adds_commented_out_greedy_matcher_to_Rails_routes_file
3
+ -----------------------------------------------------------------------------------
1
4
  -----------------------------------------------------------------------------------------
2
5
  BootstrapGeneratorTest: test_Assert_folder_layout_and_.gitkeep_files_are_properly_created
3
6
  -----------------------------------------------------------------------------------------
@@ -133,6 +136,12 @@ ScaffoldOverrideTest: test_creates_properly_namespaced_api_routes_when_api_and_v
133
136
  ---------------------------------------------------------------------------------------------------
134
137
  ScaffoldOverrideTest: test_creates_properly_namespaced_api_routes_when_api_namespace_already_exists
135
138
  ---------------------------------------------------------------------------------------------------
139
+ -------------------------------------------------------------------------------------------
140
+ ScaffoldOverrideTest: test_destroy_does_not_remove_any_non-matching_resources_or_namespaces
141
+ -------------------------------------------------------------------------------------------
142
+ ----------------------------------------------------------------------------
143
+ ScaffoldOverrideTest: test_destroy_removes_matching_resources_and_namespaces
144
+ ----------------------------------------------------------------------------
136
145
  -----------------------------------------------------------------------------
137
146
  ScaffoldOverrideTest: test_does_not_create_non-essential_files_for_ember_apps
138
147
  -----------------------------------------------------------------------------
@@ -166,18 +175,37 @@ AutoloadModulesTest: test_does_create_modules_for_directories_that_have_ruby_fil
166
175
  --------------------------------------------------------------------------------------------------
167
176
  AutoloadModulesTest: test_does_not_auto_create_modules_for_directories_that_do_not_have_ruby_files
168
177
  --------------------------------------------------------------------------------------------------
178
+ -----------------------------------------------------------------
179
+ EngineTest: test_app/assets/javascripts_is_not_in_asset_load_path
180
+ -----------------------------------------------------------------
181
+ ----------------------------------------------
182
+ EngineTest: test_app_is_in_the_asset_load_path
183
+ ----------------------------------------------
184
+ -------------------------------------------------
185
+ EngineTest: test_config_is_in_the_asset_load_path
186
+ -------------------------------------------------
187
+ -------------------------------------------------------------------------
188
+ EngineTest: test_ember_source_assets_come_after_vendor/assets/javascripts
189
+ -------------------------------------------------------------------------
190
+ ---------------------------------------------------------------------
191
+ EngineTest: test_lib/assets/javascripts_is_not_in_the_asset_load_path
192
+ ---------------------------------------------------------------------
193
+ ----------------------------------------------
194
+ EngineTest: test_lib_is_in_the_asset_load_path
195
+ ----------------------------------------------
169
196
  ----------------------------------------------------
170
197
  NavigationTest: test_can_render_default_landing_page
171
198
  ----------------------------------------------------
172
- Started GET "/" for 127.0.0.1 at 2014-01-14 14:20:37 -0500
199
+ Started GET "/" for 127.0.0.1 at 2014-01-18 16:53:20 -0500
173
200
  Processing by LandingController#index as HTML
174
- Completed 200 OK in 438ms (Views: 437.7ms)
175
- Started GET "/assets/application.css" for 127.0.0.1 at 2014-01-14 14:20:38 -0500
176
- Started GET "/assets/application.js" for 127.0.0.1 at 2014-01-14 14:20:38 -0500
201
+ Completed 200 OK in 454ms (Views: 454.1ms)
202
+ Started GET "/assets/application.css" for 127.0.0.1 at 2014-01-18 16:53:21 -0500
203
+ Started GET "/assets/application.js" for 127.0.0.1 at 2014-01-18 16:53:21 -0500
177
204
  ---------------------------------------------------
178
205
  NavigationTest: test_can_using_simple_"ember_magic"
179
206
  ---------------------------------------------------
180
- Started GET "/" for 127.0.0.1 at 2014-01-14 14:20:38 -0500
207
+ Started GET "/" for 127.0.0.1 at 2014-01-18 16:53:21 -0500
181
208
  Processing by LandingController#index as HTML
182
- Completed 200 OK in 1ms (Views: 1.1ms)
183
- Started GET "/assets/application.js" for 127.0.0.1 at 2014-01-14 14:20:38 -0500
209
+ Completed 200 OK in 1ms (Views: 1.2ms)
210
+ Started GET "/assets/application.css" for 127.0.0.1 at 2014-01-18 16:53:21 -0500
211
+ Started GET "/assets/application.js" for 127.0.0.1 at 2014-01-18 16:53:21 -0500
@@ -0,0 +1,12 @@
1
+ Dummy::Application.routes.draw do
2
+ namespace :api do
3
+ namespace :v1 do
4
+ resource :dogs, except: [:new, :edit]
5
+ end
6
+
7
+ end
8
+
9
+ namespace :dogs do
10
+
11
+ end
12
+ end
@@ -0,0 +1,76 @@
1
+ require 'parser/current'
2
+ require 'byebug'
3
+
4
+ file = File.read('routes_with_api_version_namespaces_and_route.rb')
5
+
6
+ ast = Parser::CurrentRuby.parse(file)
7
+
8
+ class RouteProcessor < AST::Processor
9
+ attr_accessor :delete_nodes
10
+
11
+ def initialize(*)
12
+ @delete_nodes = []
13
+ super
14
+ end
15
+
16
+ def handler_missing(node)
17
+ walk(node)
18
+ end
19
+
20
+ def on_block(node)
21
+ if is_namespace?(node)
22
+ if is_namespace_type?(node, :api)
23
+ walk_namespace(node)
24
+ elsif is_namespace_type?(node, :v1)
25
+ walk_namespace(node)
26
+ end
27
+ else
28
+ walk(node)
29
+ end
30
+ end
31
+
32
+ def on_send(node)
33
+ if is_resource?(node, :dogs)
34
+ delete_nodes << node
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def is_resource?(node, type)
41
+ node.children[1] == :resource && node.children[2].children.first == type.to_sym
42
+ end
43
+
44
+ def is_namespace?(node)
45
+ node.children.first.children[1] == :namespace
46
+ end
47
+
48
+ def is_namespace_type?(node, type)
49
+ node.children.first.children[2].children.first == type.to_sym
50
+ end
51
+
52
+ def walk_namespace(node)
53
+ process(node.children[2])
54
+ if node.children[2].children == delete_nodes.last.to_a
55
+ delete_nodes << node
56
+ end
57
+ end
58
+
59
+ def walk(node)
60
+ node.children.each do |child|
61
+ process(child) if child.respond_to?(:to_ast)
62
+ end
63
+ end
64
+ end
65
+
66
+ processor = RouteProcessor.new
67
+ processor.process(ast)
68
+ if processor.delete_nodes.last.loc.expression
69
+ begin_pos = processor.delete_nodes.last.loc.expression.begin_pos
70
+ end_pos = processor.delete_nodes.last.loc.expression.end_pos
71
+ else
72
+ begin_pos = processor.delete_nodes.last.loc.begin.begin_pos
73
+ end_pos = processor.delete_nodes.last.loc.end.end_pos
74
+ end
75
+ begin_pos = begin_pos - file[0..begin_pos].reverse.index("\n")
76
+ puts file.sub(file[begin_pos...end_pos], '')
@@ -7,7 +7,7 @@ class BootstrapGeneratorTest < Rails::Generators::TestCase
7
7
  tests Ember::Generators::BootstrapGenerator
8
8
  destination File.join(Rails.root, "tmp", "generator_test_output")
9
9
 
10
- setup :prepare_destination, :copy_application
10
+ setup :prepare_destination, :copy_application, :copy_routes
11
11
 
12
12
  test "Assert folder layout and .gitkeep files are properly created" do
13
13
  run_generator []
@@ -84,16 +84,24 @@ class BootstrapGeneratorTest < Rails::Generators::TestCase
84
84
  run_generator
85
85
  end
86
86
 
87
+ test "Adds commented out greedy matcher to Rails routes file" do
88
+ run_generator
89
+
90
+ assert_file 'config/routes.rb' do |content|
91
+ assert_match(/^ # get '\*foo', :to => 'landing#index'$/, content)
92
+ end
93
+ end
94
+
87
95
  private
88
96
 
89
97
  def assert_files(app_path = app_path, config_path = config_path)
90
- assert_file "#{config_path}/environment.js"
91
- assert_file "#{config_path}/environments/development.js"
92
- assert_file "#{config_path}/environments/production.js"
93
- assert_file "#{config_path}/environments/test.js"
98
+ assert_file "#{config_path}/environment.js.erb"
99
+ assert_file "#{config_path}/environments/development.js.erb"
100
+ assert_file "#{config_path}/environments/production.js.erb"
101
+ assert_file "#{config_path}/environments/test.js.erb"
94
102
  assert_file "#{config_path}/application.js"
95
103
  assert_file "#{config_path}/router.js.es6"
96
- assert_file "#{config_path}/adapter.js.erb"
104
+ assert_file "#{config_path}/adapters/application.js.es6.erb"
97
105
  assert_file "#{config_path}/initializers/csrf.js"
98
106
  end
99
107
 
@@ -23,13 +23,4 @@ class ResourceOverrideTest < Rails::Generators::TestCase
23
23
  assert_no_file "#{app_path}/helpers/posts_helper.rb"
24
24
  assert_no_directory "#{app_path}/views/posts"
25
25
  end
26
-
27
- private
28
-
29
- def copy_routes
30
- routes = File.expand_path("../../dummy/config/routes.rb", __FILE__)
31
- destination = File.expand_path('../../dummy/tmp/config', __FILE__)
32
- FileUtils.mkdir_p(destination)
33
- FileUtils.cp routes, destination
34
- end
35
26
  end
@@ -67,16 +67,32 @@ class ScaffoldOverrideTest < Rails::Generators::TestCase
67
67
  end
68
68
  end
69
69
 
70
+ test 'destroy does not remove any non-matching resources or namespaces' do
71
+ copy_routes_with_api_version_namespaces_and_route
72
+ config_content = File.read(File.expand_path('config/routes.rb', destination_root))
73
+ run_generator ['post'], behavior: :revoke
74
+
75
+ assert_file 'config/routes.rb' do |content|
76
+ assert_equal config_content, content
77
+ end
78
+ end
79
+
80
+ test 'destroy removes matching resources and namespaces' do
81
+ copy_routes_with_api_version_namespaces_and_route
82
+ config_content = File.read(File.expand_path('config/routes.rb', destination_root))
83
+ run_generator ['dogs'], behavior: :revoke
84
+
85
+ assert_file 'config/routes.rb' do |content|
86
+ refute_match(/ namespace :api do\n namespace :v1 do\n resource :dogs, except: \[:new, :edit\]\n end\n end/, content)
87
+ end
88
+ end
89
+
70
90
  private
71
91
 
72
92
  def reset_api_version
73
93
  ::Rails.application.config.ember.api_version = 1
74
94
  end
75
95
 
76
- def copy_routes
77
- copy_routes_file("../../dummy/config/routes.rb")
78
- end
79
-
80
96
  def copy_routes_with_api_namespace
81
97
  copy_routes_file("../../fixtures/routes_with_api_namespace.rb")
82
98
  end
@@ -85,10 +101,7 @@ class ScaffoldOverrideTest < Rails::Generators::TestCase
85
101
  copy_routes_file("../../fixtures/routes_with_api_and_version_namespaces.rb")
86
102
  end
87
103
 
88
- def copy_routes_file(routes_destination)
89
- routes = File.expand_path(routes_destination, __FILE__)
90
- destination = File.expand_path('../../dummy/tmp/config', __FILE__)
91
- FileUtils.mkdir_p(destination)
92
- FileUtils.cp routes, File.join(destination, 'routes.rb')
104
+ def copy_routes_with_api_version_namespaces_and_route
105
+ copy_routes_file("../../fixtures/routes_with_api_version_namespaces_and_route.rb")
93
106
  end
94
107
  end