authorized_rails_scaffolds 0.0.15 → 0.0.16

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.
@@ -29,6 +29,7 @@ module AuthorizedRailsScaffolds
29
29
 
30
30
  end
31
31
 
32
+ require "authorized_rails_scaffolds/macros/attribute_macros"
32
33
  require "authorized_rails_scaffolds/macros/controller_macros"
33
34
  require "authorized_rails_scaffolds/macros/factory_macros"
34
35
  require "authorized_rails_scaffolds/macros/path_macros"
@@ -0,0 +1,34 @@
1
+ #
2
+ # requires attributes to be defined
3
+ #
4
+ module AuthorizedRailsScaffolds::Macros::AttributeMacros
5
+
6
+ def output_attributes
7
+ unless @output_attributes
8
+ @output_attributes = []
9
+
10
+ # First attribute
11
+ @output_attributes << attributes.first unless attributes.empty?
12
+
13
+ # Reference Attribtues
14
+ @output_attributes += attributes[1..-1].reject{|attribute| ![:references].include? attribute.type }
15
+
16
+ # Standard Attributes
17
+ @output_attributes += attributes[1..-1].reject{|attribute| [:references].include? attribute.type }
18
+ end
19
+ @output_attributes
20
+ end
21
+
22
+ def references_attributes
23
+ @references_attributes ||= output_attributes.reject{|attribute| ![:references].include? attribute.type }
24
+ end
25
+
26
+ def standard_attributes
27
+ @standard_attributes ||= output_attributes.reject{|attribute| [:time, :date, :datetime, :references].include? attribute.type }
28
+ end
29
+
30
+ def datetime_attributes
31
+ @datetime_attributes ||= output_attributes.reject{|attribute| ![:time, :date, :datetime].include? attribute.type }
32
+ end
33
+
34
+ end
@@ -24,4 +24,32 @@ class AuthorizedRailsScaffolds::RSpecScaffoldHelper < AuthorizedRailsScaffolds::
24
24
  super attribute_name, variable
25
25
  end
26
26
 
27
+ def start_nesting_block
28
+ if parent_model_names.any?
29
+ "context \"within #{parent_model_names.join('/')} nesting\" do"
30
+ else
31
+ 'context do # Within default nesting'
32
+ end
33
+ end
34
+
35
+ def start_shallow_nesting_block
36
+ if shallow_routes?
37
+ 'context do # Within shallow nesting'
38
+ else
39
+ start_nesting_block
40
+ end
41
+ end
42
+
43
+ def end_nesting_block
44
+ 'end'
45
+ end
46
+
47
+ def describe_nesting_comment
48
+ if parent_model_names.any?
49
+ "within #{parent_model_names.join('/')} nesting"
50
+ else
51
+ "Within default nesting"
52
+ end
53
+ end
54
+
27
55
  end
@@ -1,24 +1,13 @@
1
1
  class AuthorizedRailsScaffolds::RSpecScaffoldViewHelper < AuthorizedRailsScaffolds::RSpecScaffoldHelper
2
+ include AuthorizedRailsScaffolds::Macros::AttributeMacros
2
3
  include AuthorizedRailsScaffolds::Macros::FactoryMacros
3
4
 
4
5
  def initialize(options = {})
5
6
  super options
6
7
  end
7
8
 
8
- def output_attributes
9
- @output_attributes ||= @attributes.reject{|attribute| [:timestamp].include? attribute.type }
10
- end
11
-
12
- def references_attributes
13
- @references_attributes ||= @attributes.reject{|attribute| ![:references].include? attribute.type }
14
- end
15
-
16
- def standard_attributes
17
- @standard_attributes ||= @attributes.reject{|attribute| [:time, :date, :datetime, :references].include? attribute.type }
18
- end
19
-
20
- def datetime_attributes
21
- @datetime_attributes ||= @attributes.reject{|attribute| ![:time, :date, :datetime].include? attribute.type }
9
+ def attributes
10
+ @attributes
22
11
  end
23
12
 
24
13
  def date_select_year_value(date_string)
@@ -1,3 +1,3 @@
1
1
  module AuthorizedRailsScaffolds
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -100,7 +100,7 @@ class <%= t_helper.controller_class_name %> < <%= t_helper.application_controlle
100
100
  format.json { render <%= key_value :json, "{ #{key_value(resource_name, resource_var)} }" %>, <%= key_value :status, ':created' %>, <%= key_value :location, t_helper.controller_show_route(resource_var) %> }
101
101
  else
102
102
  format.html { render <%= key_value :action, '"new"' %> }
103
- format.json { render <%= key_value :json, "{ " + key_value('errors', "@#{orm_instance.errors}") + " }" %>, <%= key_value :status, ':unprocessable_entity' %> }
103
+ format.json { render_json_error :unprocessable_entity, <%= key_value('errors', "@#{orm_instance.errors}") %> }
104
104
  end
105
105
  end
106
106
  end
@@ -116,7 +116,7 @@ class <%= t_helper.controller_class_name %> < <%= t_helper.application_controlle
116
116
  format.json { head :no_content }
117
117
  else
118
118
  format.html { render <%= key_value :action, '"edit"' %> }
119
- format.json { render <%= key_value :json, "{ " + key_value('errors', "@#{orm_instance.errors}") + " }" %>, <%= key_value :status, ':unprocessable_entity' %> }
119
+ format.json { render_json_error :unprocessable_entity, <%= key_value('errors', "@#{orm_instance.errors}") %> }
120
120
  end
121
121
  end
122
122
  end
@@ -163,9 +163,16 @@ class <%= t_helper.controller_class_name %> < <%= t_helper.application_controlle
163
163
  redirect_to <%= t_helper.controller_index_route %>, :alert => exception.message
164
164
  end
165
165
  end
166
- format.json { head :no_content, :status => :forbidden }
166
+ format.json { render_json_error :forbidden, <%= key_value('error', 'exception.message') %> }
167
167
  end
168
168
  end
169
169
 
170
+ def render_json_error(status_code, values = {})
171
+ json_values = {
172
+ <%= key_value('status', 'Rack::Utils.status_code(status_code)') %>
173
+ }.merge(values)
174
+ render <%= key_value('status', 'status_code') %>, <%= key_value('json', 'json_values') %>
175
+ end
176
+
170
177
  end
171
178
  <% end -%>
@@ -73,7 +73,7 @@ describe <%= t_helper.controller_class_name %> do
73
73
  <%- end -%>
74
74
  <% unless options[:singleton] -%>
75
75
  describe "GET index" do
76
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
76
+ <%= t_helper.start_nesting_block %>
77
77
  <%- t_helper.parent_models.each do |parent_model| -%>
78
78
  grant_ability :read, <%= parent_model.classify %>
79
79
  <%- end -%>
@@ -116,12 +116,12 @@ describe <%= t_helper.controller_class_name %> do
116
116
  end
117
117
  end
118
118
  end
119
- end
119
+ <%= t_helper.end_nesting_block %>
120
120
  end
121
121
 
122
122
  <% end -%>
123
123
  describe "GET show" do
124
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
124
+ <%= t_helper.start_shallow_nesting_block %>
125
125
  <%- parent_model_names.each do |parent_model| -%>
126
126
  grant_ability :read, <%= parent_model.classify %>
127
127
  <%- end -%>
@@ -163,12 +163,19 @@ describe <%= t_helper.controller_class_name %> do
163
163
  assigns(<%= resource_symbol %>).should eq(<%= resource_test_var %>)
164
164
  end
165
165
  end
166
+ describe 'with request for missing <%= resource_human_name %>' do
167
+ it "raises a ActiveRecord::RecordNotFound when no <%= resource_human_name %> is found" do
168
+ expect {
169
+ get :show, {<%= t_helper.build_example_show_params ":id => #{(10..99).to_a.sample}" %>}
170
+ }.to raise_exception(ActiveRecord::RecordNotFound)
171
+ end
172
+ end
166
173
  end
167
- end
174
+ <%= t_helper.end_nesting_block %>
168
175
  end
169
176
 
170
177
  describe "GET new" do
171
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
178
+ <%= t_helper.start_nesting_block %>
172
179
  <%- parent_model_names.each do |parent_model| -%>
173
180
  grant_ability :read, <%= parent_model.classify %>
174
181
  <%- end -%>
@@ -208,11 +215,11 @@ describe <%= t_helper.controller_class_name %> do
208
215
  end
209
216
  end
210
217
  end
211
- end
218
+ <%= t_helper.end_nesting_block %>
212
219
  end
213
220
 
214
221
  describe "GET edit" do
215
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
222
+ <%= t_helper.start_shallow_nesting_block %>
216
223
  <%- parent_model_names.each do |parent_model| -%>
217
224
  grant_ability :read, <%= parent_model.classify %>
218
225
  <%- end -%>
@@ -255,11 +262,11 @@ describe <%= t_helper.controller_class_name %> do
255
262
  end
256
263
  end
257
264
  end
258
- end
265
+ <%= t_helper.end_nesting_block %>
259
266
  end
260
267
 
261
268
  describe "POST create" do
262
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
269
+ <%= t_helper.start_nesting_block %>
263
270
  <%- parent_model_names.each do |parent_model| -%>
264
271
  grant_ability :read, <%= parent_model.classify %>
265
272
  <%- end -%>
@@ -325,11 +332,11 @@ describe <%= t_helper.controller_class_name %> do
325
332
  end
326
333
  end
327
334
  end
328
- end
335
+ <%= t_helper.end_nesting_block %>
329
336
  end
330
337
 
331
338
  describe "PUT update" do
332
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
339
+ <%= t_helper.start_shallow_nesting_block %>
333
340
  <%- parent_model_names.each do |parent_model| -%>
334
341
  grant_ability :read, <%= parent_model.classify %>
335
342
  <%- end -%>
@@ -401,11 +408,11 @@ describe <%= t_helper.controller_class_name %> do
401
408
  end
402
409
  end
403
410
  end
404
- end
411
+ <%= t_helper.end_nesting_block %>
405
412
  end
406
413
 
407
414
  describe "DELETE destroy" do
408
- context <% if parent_model_names.any? %>"within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
415
+ <%= t_helper.start_shallow_nesting_block %>
409
416
  <%- parent_model_names.each do |parent_model| -%>
410
417
  grant_ability :read, <%= parent_model.classify %>
411
418
  <%- end -%>
@@ -452,7 +459,7 @@ describe <%= t_helper.controller_class_name %> do
452
459
  end
453
460
  end
454
461
  end
455
- end
462
+ <%= t_helper.end_nesting_block %>
456
463
  end
457
464
 
458
465
  end
@@ -51,7 +51,7 @@ describe "<%= resource_directory %>/edit" do
51
51
  controller.stub(:current_ability) { @ability }
52
52
  end
53
53
 
54
- context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
54
+ <%= t_helper.start_shallow_nesting_block %>
55
55
  before(:each) do
56
56
  # Add Properties for view scope
57
57
  <%- parent_model_names.each do |parent_model| -%>
@@ -133,5 +133,5 @@ describe "<%= resource_directory %>/edit" do
133
133
  end
134
134
 
135
135
  <% end -%>
136
- end
136
+ <%= t_helper.end_nesting_block %>
137
137
  end
@@ -52,7 +52,7 @@ describe "<%= resource_directory %>/index" do
52
52
  controller.stub(:current_ability) { @ability }
53
53
  end
54
54
 
55
- context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
55
+ <%= t_helper.start_nesting_block %>
56
56
  before(:each) do
57
57
  # Add Properties for view scope
58
58
  <%- parent_model_names.each do |parent_model| -%>
@@ -236,6 +236,6 @@ describe "<%= resource_directory %>/index" do
236
236
  end
237
237
  end
238
238
  end
239
- end
239
+ <%= t_helper.end_nesting_block %>
240
240
 
241
241
  end
@@ -49,7 +49,7 @@ describe "<%= resource_directory %>/new" do
49
49
  controller.stub(:current_ability) { @ability }
50
50
  end
51
51
 
52
- context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
52
+ <%= t_helper.start_nesting_block %>
53
53
  before(:each) do
54
54
  # Add Properties for view scope
55
55
  <%- parent_model_names.each do |parent_model| -%>
@@ -130,5 +130,5 @@ describe "<%= resource_directory %>/new" do
130
130
  <% end -%>
131
131
  end
132
132
  <% end -%>
133
- end
133
+ <%= t_helper.end_nesting_block %>
134
134
  end
@@ -51,7 +51,7 @@ describe "<%= resource_directory %>/show" do
51
51
  controller.stub(:current_ability) { @ability }
52
52
  end
53
53
 
54
- context<% if parent_model_names.any? %> "within <%= parent_model_names.join('/') %> nesting"<% end %> do<%- unless parent_model_names.any? -%> # Within default nesting<% end %>
54
+ <%= t_helper.start_nesting_block %>
55
55
  before(:each) do
56
56
  # Add Properties for view scope
57
57
  <%- parent_model_names.each do |parent_model| -%>
@@ -119,6 +119,6 @@ describe "<%= resource_directory %>/show" do
119
119
  end
120
120
  end
121
121
  <% end -%>
122
- end
122
+ <%= t_helper.end_nesting_block %>
123
123
 
124
124
  end
metadata CHANGED
@@ -1,85 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authorized_rails_scaffolds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - bmorrall
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-20 00:00:00.000000000 Z
12
+ date: 2013-06-08 00:00:00.000000000Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: railties
15
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70151610121940 !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3.1'
20
22
  type: :runtime
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '3.1'
24
+ version_requirements: *70151610121940
27
25
  - !ruby/object:Gem::Dependency
28
26
  name: rails
29
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70151610120260 !ruby/object:Gem::Requirement
28
+ none: false
30
29
  requirements:
31
30
  - - ! '>='
32
31
  - !ruby/object:Gem::Version
33
32
  version: '3.1'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '3.1'
35
+ version_requirements: *70151610120260
41
36
  - !ruby/object:Gem::Dependency
42
37
  name: bundler
43
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70151610115080 !ruby/object:Gem::Requirement
39
+ none: false
44
40
  requirements:
45
41
  - - ~>
46
42
  - !ruby/object:Gem::Version
47
43
  version: '1.3'
48
44
  type: :development
49
45
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '1.3'
46
+ version_requirements: *70151610115080
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: rake
57
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70151610113780 !ruby/object:Gem::Requirement
50
+ none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  type: :development
63
56
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
57
+ version_requirements: *70151610113780
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: rspec
71
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70151610112440 !ruby/object:Gem::Requirement
61
+ none: false
72
62
  requirements:
73
63
  - - ! '>='
74
64
  - !ruby/object:Gem::Version
75
65
  version: '0'
76
66
  type: :development
77
67
  prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
68
+ version_requirements: *70151610112440
83
69
  description: Creates scaffolds for Twitter Bootstrap with generated RSpec coverage
84
70
  email:
85
71
  - bemo56@hotmail.com
@@ -95,6 +81,7 @@ files:
95
81
  - authorized_rails_scaffolds.gemspec
96
82
  - lib/authorized_rails_scaffolds.rb
97
83
  - lib/authorized_rails_scaffolds/helper.rb
84
+ - lib/authorized_rails_scaffolds/macros/attribute_macros.rb
98
85
  - lib/authorized_rails_scaffolds/macros/controller_macros.rb
99
86
  - lib/authorized_rails_scaffolds/macros/factory_macros.rb
100
87
  - lib/authorized_rails_scaffolds/macros/parent_macros.rb
@@ -148,26 +135,27 @@ files:
148
135
  homepage: https://github.com/bmorrall/authorized_rails_scaffolds
149
136
  licenses:
150
137
  - MIT
151
- metadata: {}
152
138
  post_install_message:
153
139
  rdoc_options: []
154
140
  require_paths:
155
141
  - lib
156
142
  required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
157
144
  requirements:
158
145
  - - ! '>='
159
146
  - !ruby/object:Gem::Version
160
147
  version: '0'
161
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
162
150
  requirements:
163
151
  - - ! '>='
164
152
  - !ruby/object:Gem::Version
165
153
  version: '0'
166
154
  requirements: []
167
155
  rubyforge_project:
168
- rubygems_version: 2.0.3
156
+ rubygems_version: 1.8.10
169
157
  signing_key:
170
- specification_version: 4
158
+ specification_version: 3
171
159
  summary: Replaces Rails and RSpec's default generators with templates taking full
172
160
  advantage of Authentication (Devise), Authorization (CanCan) and Test Coverage (RSpec)
173
161
  test_files:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 48159be8830cab29219981b558c48f647cac5651
4
- data.tar.gz: 31db50aea7a19dfa206edc4b9eb0dcff5e20d48a
5
- SHA512:
6
- metadata.gz: 01f6d37305d7e270d045d18f833130b14ed50086bd8e03b83e1364496272437dc8a0d7e2d1e06ae536aca9c6e519626d8ad8271af7be6c353353feaf93e0a1fa
7
- data.tar.gz: 90483813b42dbb7437d30f4e56782782988babdf1423c7825d3dabfefdcdc9a225c6cdf172fe97767ece17a211cbd371e4a92d4bb7214b872af6a817ef88f997