daylight 0.9.0.rc1

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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +113 -0
  3. data/app/controllers/daylight_documentation/documentation_controller.rb +27 -0
  4. data/app/helpers/daylight_documentation/documentation_helper.rb +57 -0
  5. data/app/views/daylight_documentation/documentation/_header.haml +4 -0
  6. data/app/views/daylight_documentation/documentation/index.haml +12 -0
  7. data/app/views/daylight_documentation/documentation/model.haml +114 -0
  8. data/app/views/layouts/documentation.haml +22 -0
  9. data/config/routes.rb +8 -0
  10. data/doc/actions.md +70 -0
  11. data/doc/benchmarks.md +17 -0
  12. data/doc/contribute.md +80 -0
  13. data/doc/develop.md +1205 -0
  14. data/doc/environment.md +109 -0
  15. data/doc/example.md +3 -0
  16. data/doc/framework.md +31 -0
  17. data/doc/install.md +128 -0
  18. data/doc/principles.md +42 -0
  19. data/doc/testing.md +107 -0
  20. data/doc/usage.md +970 -0
  21. data/lib/daylight/api.rb +293 -0
  22. data/lib/daylight/associations.rb +247 -0
  23. data/lib/daylight/client_reloader.rb +45 -0
  24. data/lib/daylight/collection.rb +161 -0
  25. data/lib/daylight/errors.rb +94 -0
  26. data/lib/daylight/inflections.rb +7 -0
  27. data/lib/daylight/mock.rb +282 -0
  28. data/lib/daylight/read_only.rb +88 -0
  29. data/lib/daylight/refinements.rb +63 -0
  30. data/lib/daylight/reflection_ext.rb +67 -0
  31. data/lib/daylight/resource_proxy.rb +226 -0
  32. data/lib/daylight/version.rb +10 -0
  33. data/lib/daylight.rb +27 -0
  34. data/rails/daylight/api_controller.rb +354 -0
  35. data/rails/daylight/documentation.rb +13 -0
  36. data/rails/daylight/helpers.rb +32 -0
  37. data/rails/daylight/params.rb +23 -0
  38. data/rails/daylight/refiners.rb +186 -0
  39. data/rails/daylight/server.rb +29 -0
  40. data/rails/daylight/tasks.rb +37 -0
  41. data/rails/extensions/array_ext.rb +9 -0
  42. data/rails/extensions/autosave_association_fix.rb +49 -0
  43. data/rails/extensions/has_one_serializer_ext.rb +111 -0
  44. data/rails/extensions/inflections.rb +6 -0
  45. data/rails/extensions/nested_attributes_ext.rb +94 -0
  46. data/rails/extensions/read_only_attributes.rb +35 -0
  47. data/rails/extensions/render_json_meta.rb +99 -0
  48. data/rails/extensions/route_options.rb +47 -0
  49. data/rails/extensions/versioned_url_for.rb +22 -0
  50. data/spec/config/dependencies.rb +2 -0
  51. data/spec/config/factory_girl.rb +4 -0
  52. data/spec/config/simplecov_rcov.rb +26 -0
  53. data/spec/config/test_api.rb +1 -0
  54. data/spec/controllers/documentation_controller_spec.rb +24 -0
  55. data/spec/dummy/README.rdoc +28 -0
  56. data/spec/dummy/Rakefile +6 -0
  57. data/spec/dummy/app/assets/images/.keep +0 -0
  58. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  59. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  60. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  61. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  62. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  63. data/spec/dummy/app/mailers/.keep +0 -0
  64. data/spec/dummy/app/models/.keep +0 -0
  65. data/spec/dummy/app/models/concerns/.keep +0 -0
  66. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  67. data/spec/dummy/bin/bundle +3 -0
  68. data/spec/dummy/bin/rails +4 -0
  69. data/spec/dummy/bin/rake +4 -0
  70. data/spec/dummy/config/application.rb +24 -0
  71. data/spec/dummy/config/boot.rb +5 -0
  72. data/spec/dummy/config/database.yml +25 -0
  73. data/spec/dummy/config/environment.rb +5 -0
  74. data/spec/dummy/config/environments/development.rb +29 -0
  75. data/spec/dummy/config/environments/production.rb +80 -0
  76. data/spec/dummy/config/environments/test.rb +36 -0
  77. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  78. data/spec/dummy/config/initializers/daylight.rb +1 -0
  79. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  80. data/spec/dummy/config/initializers/inflections.rb +16 -0
  81. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  82. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  83. data/spec/dummy/config/initializers/session_store.rb +3 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/dummy/config/locales/en.yml +23 -0
  86. data/spec/dummy/config/routes.rb +59 -0
  87. data/spec/dummy/config.ru +4 -0
  88. data/spec/dummy/lib/assets/.keep +0 -0
  89. data/spec/dummy/log/.keep +0 -0
  90. data/spec/dummy/public/404.html +58 -0
  91. data/spec/dummy/public/422.html +58 -0
  92. data/spec/dummy/public/500.html +57 -0
  93. data/spec/dummy/public/favicon.ico +0 -0
  94. data/spec/helpers/documentation_helper_spec.rb +82 -0
  95. data/spec/lib/daylight/api_spec.rb +178 -0
  96. data/spec/lib/daylight/associations_spec.rb +325 -0
  97. data/spec/lib/daylight/collection_spec.rb +235 -0
  98. data/spec/lib/daylight/errors_spec.rb +111 -0
  99. data/spec/lib/daylight/mock_spec.rb +144 -0
  100. data/spec/lib/daylight/read_only_spec.rb +118 -0
  101. data/spec/lib/daylight/refinements_spec.rb +80 -0
  102. data/spec/lib/daylight/reflection_ext_spec.rb +50 -0
  103. data/spec/lib/daylight/resource_proxy_spec.rb +325 -0
  104. data/spec/rails/daylight/api_controller_spec.rb +421 -0
  105. data/spec/rails/daylight/helpers_spec.rb +41 -0
  106. data/spec/rails/daylight/params_spec.rb +45 -0
  107. data/spec/rails/daylight/refiners_spec.rb +178 -0
  108. data/spec/rails/extensions/array_ext_spec.rb +51 -0
  109. data/spec/rails/extensions/has_one_serializer_ext_spec.rb +135 -0
  110. data/spec/rails/extensions/nested_attributes_ext_spec.rb +177 -0
  111. data/spec/rails/extensions/render_json_meta_spec.rb +140 -0
  112. data/spec/rails/extensions/route_options_spec.rb +309 -0
  113. data/spec/rails/extensions/versioned_url_for_spec.rb +46 -0
  114. data/spec/spec_helper.rb +43 -0
  115. data/spec/support/migration_helper.rb +40 -0
  116. metadata +422 -0
@@ -0,0 +1,309 @@
1
+ require 'spec_helper'
2
+
3
+ class TestAssociatedRouteController < ActionController::Base
4
+ def associated
5
+ render text: [params[:controller], params[:id], params[:associated]].join('/')
6
+ end
7
+ end
8
+
9
+ class TestAssociatedRoutesController < TestAssociatedRouteController
10
+ def associated
11
+ render text: [params[:controller], params[:associated]].join('/')
12
+ end
13
+ end
14
+
15
+ class TestMethodRoute < ActiveRecord::Base;
16
+ def foo; end
17
+ def bar; end
18
+ end
19
+
20
+ class TestMethodRouteController < ActionController::Base
21
+ def remoted
22
+ render text: [params[:controller], params[:id], params[:remoted]].join('/')
23
+ end
24
+ end
25
+
26
+ class TestAltModel < ActiveRecord::Base;
27
+ def foo; end
28
+ def bar; end
29
+ end
30
+
31
+ class TestMethodRouteAltModelController < ActionController::Base
32
+ def self.model
33
+ TestAltModel
34
+ end
35
+
36
+ def remoted
37
+ render text: [params[:controller], params[:id], params[:remoted]].join('/')
38
+ end
39
+ end
40
+
41
+ describe RouteOptions, type: [:controller, :routing] do
42
+
43
+ after :all do
44
+ Rails.application.reload_routes!
45
+ end
46
+
47
+ describe 'associated on resources' do
48
+ # rspec's controller temporarily wipes out routes and recreates
49
+ # routes for the anonymnous controller, we don't want to do that
50
+ # also, rspec-rails does not honor the tests(controller) function
51
+ def self.controller_class
52
+ TestAssociatedRouteController
53
+ end
54
+
55
+ describe 'with one route' do
56
+
57
+ before do
58
+ @routes.draw do
59
+ resources :test_associated_route, associated: %w[bars]
60
+ end
61
+ end
62
+
63
+ it 'adds associated route' do
64
+ expect(get: '/test_associated_route/1/bars').to route_to(
65
+
66
+ controller: 'test_associated_route',
67
+ action: 'associated',
68
+ id: '1',
69
+ associated: 'bars'
70
+ )
71
+ end
72
+
73
+ it 'respsonds to associated with expected params' do
74
+ get :associated, id: 1, associated: 'bars'
75
+
76
+ assert_response :success
77
+
78
+ response.body.should == 'test_associated_route/1/bars'
79
+ end
80
+
81
+ it 'sets up named link helpers' do
82
+ bars_test_associated_route_path(10).should == '/test_associated_route/10/bars'
83
+ end
84
+ end
85
+
86
+ describe 'with multiple routes' do
87
+
88
+ before do
89
+ @routes.draw do
90
+ resources :test_associated_route, associated: %w[bars wibbles]
91
+ end
92
+ end
93
+
94
+ it 'adds first associated route' do
95
+ expect(get: '/test_associated_route/1/bars').to route_to(
96
+
97
+ controller: 'test_associated_route',
98
+ action: 'associated',
99
+ id: '1',
100
+ associated: 'bars'
101
+ )
102
+ end
103
+
104
+ it 'respsonds to first associated with expected params' do
105
+ get :associated, id: 1, associated: 'bars'
106
+
107
+ assert_response :success
108
+ response.body.should == 'test_associated_route/1/bars'
109
+ end
110
+
111
+ it 'sets up first named link helpers' do
112
+ bars_test_associated_route_path(11).should == '/test_associated_route/11/bars'
113
+ end
114
+
115
+
116
+ it 'adds last associated route' do
117
+ expect(get: '/test_associated_route/1/wibbles').to route_to(
118
+
119
+ controller: 'test_associated_route',
120
+ action: 'associated',
121
+ id: '1',
122
+ associated: 'wibbles'
123
+ )
124
+ end
125
+
126
+ it 'respsonds to last associated with expected params' do
127
+ get :associated, id: 1, associated: 'wibbles'
128
+
129
+ assert_response :success
130
+ response.body.should == 'test_associated_route/1/wibbles'
131
+ end
132
+
133
+ it 'sets up last named link helpers' do
134
+ wibbles_test_associated_route_path(11).should == '/test_associated_route/11/wibbles'
135
+ end
136
+ end
137
+ end
138
+
139
+ describe 'associated on resource' do
140
+ # rspec's controller temporarily wipes out routes and recreates
141
+ # routes for the anonymnous controller, we don't want to do that
142
+ # also, rspec-rails does not honor the tests(controller) function
143
+ def self.controller_class
144
+ TestAssociatedRoutesController
145
+ end
146
+
147
+
148
+ describe 'with one route' do
149
+
150
+ before do
151
+ @routes.draw do
152
+ resource :test_associated_route, associated: %w[bars]
153
+ end
154
+ end
155
+
156
+ it 'adds associated route' do
157
+ expect(get: '/test_associated_route/bars').to route_to(
158
+
159
+ controller: 'test_associated_routes',
160
+ action: 'associated',
161
+ associated: 'bars'
162
+ )
163
+ end
164
+
165
+ it 'respsonds to associated with expected params' do
166
+ get :associated, associated: 'bars'
167
+
168
+ assert_response :success
169
+
170
+ response.body.should == 'test_associated_routes/bars'
171
+ end
172
+
173
+ it 'sets up named link helpers' do
174
+ bars_test_associated_route_path.should == '/test_associated_route/bars'
175
+ end
176
+ end
177
+
178
+ describe 'with multiple routes' do
179
+
180
+ before do
181
+ @routes.draw do
182
+ resource :test_associated_route, associated: %w[bars wibbles]
183
+ end
184
+ end
185
+
186
+ it 'adds first associated route' do
187
+ expect(get: '/test_associated_route/bars').to route_to(
188
+
189
+ controller: 'test_associated_routes',
190
+ action: 'associated',
191
+ associated: 'bars'
192
+ )
193
+ end
194
+
195
+ it 'respsonds to first associated with expected params' do
196
+ get :associated, associated: 'bars'
197
+
198
+ assert_response :success
199
+ response.body.should == 'test_associated_routes/bars'
200
+ end
201
+
202
+ it 'sets up first named link helpers' do
203
+ bars_test_associated_route_path.should == '/test_associated_route/bars'
204
+ end
205
+
206
+
207
+ it 'adds last associated route' do
208
+ expect(get: '/test_associated_route/wibbles').to route_to(
209
+
210
+ controller: 'test_associated_routes',
211
+ action: 'associated',
212
+ associated: 'wibbles'
213
+ )
214
+ end
215
+
216
+ it 'respsonds to last associated with expected params' do
217
+ get :associated, associated: 'wibbles'
218
+
219
+ assert_response :success
220
+ response.body.should == 'test_associated_routes/wibbles'
221
+ end
222
+
223
+ it 'sets up last named link helpers' do
224
+ wibbles_test_associated_route_path.should == '/test_associated_route/wibbles'
225
+ end
226
+ end
227
+ end
228
+
229
+ describe "remoted resource" do
230
+ # rspec's controller temporarily wipes out routes and recreates
231
+ # routes for the anonymnous controller, we don't want to do that
232
+ # also, rspec-rails does not honor the tests(controller) function
233
+ def self.controller_class
234
+ TestMethodRouteController
235
+ end
236
+
237
+ before do
238
+ @routes.draw do
239
+ resources :test_method_route, remoted: %w[foo]
240
+ end
241
+ end
242
+
243
+ it 'adds associated route' do
244
+ expect(get: '/test_method_route/1/foo').to route_to(
245
+ controller: 'test_method_route',
246
+ action: 'remoted',
247
+ id: '1',
248
+ remoted: 'foo'
249
+ )
250
+ end
251
+
252
+ it 'respsonds to method with expected params' do
253
+ get :remoted, id: 1, remoted: 'foo'
254
+
255
+ assert_response :success
256
+
257
+ response.body.should == 'test_method_route/1/foo'
258
+ end
259
+
260
+ it 'sets up named link helpers' do
261
+ foo_test_method_route_path(10).should == '/test_method_route/10/foo'
262
+ end
263
+
264
+ it 'keeps track for remoted methods on the controller' do
265
+ TestMethodRoute.remoted?(:foo).should be_true
266
+ end
267
+ end
268
+
269
+ describe "remoted resource with alternate model" do
270
+ # rspec's controller temporarily wipes out routes and recreates
271
+ # routes for the anonymnous controller, we don't want to do that
272
+ # also, rspec-rails does not honor the tests(controller) function
273
+ def self.controller_class
274
+ TestMethodRouteAltModelController
275
+ end
276
+
277
+ before do
278
+ @routes.draw do
279
+ resources :test_method_route_alt_model, remoted: %w[bar]
280
+ end
281
+ end
282
+
283
+ it 'adds associated route' do
284
+ expect(get: '/test_method_route_alt_model/1/bar').to route_to(
285
+ controller: 'test_method_route_alt_model',
286
+ action: 'remoted',
287
+ id: '1',
288
+ remoted: 'bar'
289
+ )
290
+ end
291
+
292
+ it 'respsonds to method with expected params' do
293
+ get :remoted, id: 1, remoted: 'bar'
294
+
295
+ assert_response :success
296
+
297
+ response.body.should == 'test_method_route_alt_model/1/bar'
298
+ end
299
+
300
+ it 'sets up named link helpers' do
301
+ bar_test_method_route_alt_model_path(10).should == '/test_method_route_alt_model/10/bar'
302
+ end
303
+
304
+ it 'keeps track for remoted methods on the controller' do
305
+ TestAltModel.remoted?(:bar).should be_true
306
+ end
307
+ end
308
+
309
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe VersionedUrlFor do
4
+
5
+ class VersionedModelTest
6
+ attr_accessor :to_param
7
+ def initialize(id)
8
+ @to_param = id
9
+ end
10
+
11
+ def to_model
12
+ self
13
+ end
14
+ end
15
+
16
+ module API
17
+ module V1
18
+ class TestVersionsController < ActionController::Base
19
+ include VersionedUrlFor
20
+
21
+ def api_v1_test_version_path model
22
+ "/v1/test/#{model.to_param}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ let(:controller) { API::V1::TestVersionsController.new }
29
+ let(:model) { VersionedModelTest.new(1) }
30
+
31
+
32
+ it 'defines versioned name / path based on controller name' do
33
+ controller.send(:versioned_name).should == 'api_v1_test_version'
34
+ controller.send(:versioned_path).should == 'api_v1_test_version_path'
35
+ end
36
+
37
+ it 'uses overriden url_for for models' do
38
+ controller.send(:versioned_url_for, model).should == '/v1/test/1'
39
+ controller.send(:url_for, model).should == '/v1/test/1'
40
+ end
41
+
42
+ it 'uses regular url_for if not a model' do
43
+ controller.should_receive(:url_for).with(action: 'foo').and_return('/path')
44
+ controller.send(:url_for, action: 'foo').should == '/path'
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # Simplecov must be loaded before environment
4
+ require File.expand_path('spec/config/simplecov_rcov')
5
+
6
+ # load the dummy rails environment
7
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
8
+
9
+ require 'rspec/rails'
10
+ require 'rspec/autorun'
11
+
12
+ require 'webmock/rspec'
13
+
14
+ WebMock.disable_net_connect!
15
+
16
+ # Load additional rspec configuration files first
17
+ Dir.glob(File.expand_path('../config/**/*.rb', __FILE__)).each { |f| require f }
18
+
19
+ # Requires supporting ruby files with custom matchers and macros, etc,
20
+ # in spec/support/ and its subdirectories.
21
+ Dir.glob(File.expand_path('../support/**/*.rb', __FILE__)).each { |f| require f }
22
+
23
+ # make unpermitted parameters raise exceptions so we can test them!
24
+ # See https://github.com/att-cloud/daylight/issues/8
25
+ ActionController::Parameters.action_on_unpermitted_parameters = :raise
26
+
27
+ RSpec.configure do |config|
28
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
29
+ # examples within a transaction, remove the following line or assign false
30
+ # instead of true.
31
+ config.use_transactional_fixtures = true
32
+
33
+ # If true, the base class of anonymous controllers will be inferred
34
+ # automatically. This will be the default behavior in future versions of
35
+ # rspec-rails.
36
+ config.infer_base_class_for_anonymous_controllers = false
37
+
38
+ # Run specs in random order to surface order dependencies. If you find an
39
+ # order dependency and want to debug it, you can fix the order by providing
40
+ # the seed, which is printed after each run.
41
+ # --seed 1234
42
+ config.order = "random"
43
+ end
@@ -0,0 +1,40 @@
1
+ module MigrationHelper
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ attr_accessor :migrations
6
+
7
+ def migrate &block
8
+ migrations << Class.new(ActiveRecord::Migration) do
9
+ define_method :change, &block
10
+ end
11
+ end
12
+
13
+ def migrations
14
+ @migrations ||= []
15
+ end
16
+ end
17
+
18
+ included do
19
+ before(:all) do
20
+ self.class.migrations.each do |migration|
21
+ ActiveRecord::Migration.suppress_messages do
22
+ migration.migrate(:up)
23
+ end
24
+ end
25
+ end
26
+
27
+ after(:all) do
28
+ self.class.migrations.each do |migration|
29
+ ActiveRecord::Migration.suppress_messages do
30
+ migration.migrate(:down)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ RSpec.configure do |config|
39
+ config.include MigrationHelper
40
+ end