kitestrings 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5e7e7b1e26fec5ba18d84498ad21faf270e378f
4
- data.tar.gz: 7e9c7e8e8c0879534bde9063c9842f4ddccd9e7e
3
+ metadata.gz: cf0df7d83a5a0c5091ed7e02be33fef6935451ab
4
+ data.tar.gz: 4d1053d2a099ff58146624a6096ac0fb49fda3fa
5
5
  SHA512:
6
- metadata.gz: 18fbd306f921ce2bbdb45acfae7a7e2e301d53ad1b3e23a638e53a96c697371b034c0e17ee22a9385ca95c0b6c8c45abb722c069b4e8ac04f17699205cfe6d1e
7
- data.tar.gz: 9ca876d4e6842c11e225f8fb58c41903436d524de0cff886d44c7f847f6168451a2437592b62f5aa14cabeb597310b3cd2f388aba27ea6c4809b357a547777b2
6
+ metadata.gz: 82ed8582b3f2b57e4b5558a71ba6a1a04a7580e80fdd98492214939edb6910d2ca8f3d9141639724351143daeb214454feca0751bdc2a68b22e2adcdd0a5a753
7
+ data.tar.gz: 4689a336367cce7149d6c6d96373052ede184e3cd35503ee55fb3f2c4e7f2ab2a2bc977663bf11cef0345d74dd30eea2786f7610ff749123120efdaf0314e661
@@ -1,7 +1,12 @@
1
1
  # Version history:
2
2
 
3
3
  ## 1.2.1
4
- * change to fixturen
4
+ * rewrite of controller spec to use metadata
5
+ * default ability
6
+ * nested_cancan
7
+
8
+ ## 1.2.1
9
+ * change to fixtures
5
10
  * scaffold generators cleaned up (rspec 3)
6
11
 
7
12
  ## 1.2.0
@@ -31,6 +31,10 @@ module Kitestrings
31
31
  directory "rails", "lib/templates/rails"
32
32
  end
33
33
 
34
+ def copy_lib_files
35
+ directory "lib", "lib"
36
+ end
37
+
34
38
  def copy_rspec_files
35
39
  directory "rspec", "lib/templates/rspec"
36
40
  end
@@ -43,16 +47,43 @@ module Kitestrings
43
47
  directory "support", "spec/support"
44
48
  end
45
49
 
50
+ def copy_rake_task_files
51
+ directory "tasks", "lib/tasks"
52
+ end
53
+
46
54
  def copy_app_view_files
47
55
  copy_file "views/application/_navigation.html.haml", "app/views/application/_navigation.html.haml"
48
56
  copy_file "views/layouts/application.html.haml", "app/views/layouts/application.html.haml"
49
57
  copy_file "views/public/403.html", "app/views/public/403.html"
50
58
  end
51
59
 
60
+ # def setup_abilities_with_default_role
61
+ # inject_into_file "app/models/ability.rb" do #, :after => /def initialize(user).*$/ do
62
+ # "\n"\
63
+ # " case user.role\n"\
64
+ # " when :default\n"\
65
+ # " can :manage, :all\n"\
66
+ # " end\n"\
67
+ #
68
+ # end
69
+ # end
70
+
71
+ def setup_abilities_with_default_role
72
+ insert_into_file "app/models/ability.rb", :after => "def initialize(user)" do
73
+ "\n"\
74
+ " case user.role\n"\
75
+ " when :default\n"\
76
+ " can :manage, :all\n"\
77
+ " end\n"\
78
+
79
+ end
80
+ end
81
+
52
82
  def setup_application_controller
53
83
  inject_into_file "app/controllers/application_controller.rb", :after => /protect_from_forgery.*$/ do
54
84
  "
55
85
  respond_to :html
86
+ include NestedLoadAndAuthorize
56
87
 
57
88
  unless Rails.application.config.consider_all_requests_local
58
89
  rescue_from CanCan::AccessDenied do |exception|
@@ -75,6 +106,8 @@ config.generators do |g|
75
106
  config.app_generators do |g|
76
107
  g.templates.unshift File.expand_path('../lib/templates', __FILE__)
77
108
  end
109
+
110
+ config.autoload_paths += %W(\#{config.root}/lib)
78
111
  END
79
112
 
80
113
  environment generators_configuration
@@ -0,0 +1,68 @@
1
+ module NestedLoadAndAuthorize
2
+ # load and authorise the resource with the same parameters as the Can Can controller additions
3
+ # class macro load_and_authorize_resource.
4
+ #
5
+ # This differs in that it is an instance method, so you must call it in a before_filter (or
6
+ # from another instance method).
7
+ #
8
+ # This method has no effect if the resource is already loaded.
9
+ #
10
+ # Any block passed to this method will be executed if the resource was successfully loaded by
11
+ # this call. Nested calls automatically supply the +:through+ parameter. To bypass this, set
12
+ # :through => nil.
13
+ # rubocop:disable
14
+ def load_and_authorize(name, options = {})
15
+ @_through_stack ||= []
16
+
17
+ # only touch can can if the instance variable is nil
18
+ resource = instance_variable_get("@#{name}")
19
+ if resource.nil?
20
+ # apply if, only and except behaviours just is if this was done by before_filter
21
+ proceed = true
22
+ proceed &&= [*options[:only]].include?(action_name.to_sym) if options[:only]
23
+ proceed &&= ![*options[:except]].include?(action_name.to_sym) if options[:except]
24
+ proceed &&= case options[:if]
25
+ when Symbol
26
+ send(options[:if])
27
+ when Proc
28
+ options[:if].call
29
+ when nil
30
+ true
31
+ end
32
+
33
+ if proceed
34
+ # automatically load this resource through a nested one unless manually specified
35
+ options[:through] = @_through_stack.last unless @_through_stack.empty? || options.include?(:through)
36
+ # create the can can resource class
37
+ cancan = self.class.cancan_resource_class.new(self, name, options.except(:if, :only, :except, :param))
38
+ resource = cancan.load_resource
39
+ cancan.authorize_resource unless options[:skip_authorize]
40
+ if resource && block_given?
41
+ # only call block if we got an instance variable set
42
+ begin
43
+ @_through_stack.push(name)
44
+ yield
45
+ ensure
46
+ @_through_stack.pop
47
+ end
48
+ end
49
+ end
50
+ end
51
+ resource
52
+ end
53
+
54
+ # syntactic sugar for adding the :skip_authorize option
55
+ def load_resource(name, options = {}, &block)
56
+ options[:skip_authorize] = true
57
+ load_and_authorize(name, options, &block)
58
+ end
59
+
60
+ # load the resource only if its request parameter is present. This allows for optional nesting to
61
+ # work like shallow routes with the before_filter way of doing things.
62
+ def load_and_authorize_if_present(name, options = {}, &block)
63
+ key = options[:id_param] || "#{name}_id"
64
+ if params[key]
65
+ load_and_authorize(name, options, &block)
66
+ end
67
+ end
68
+ end
@@ -4,17 +4,20 @@ require_dependency "<%= namespaced_file_path %>/application_controller"
4
4
  <% end -%>
5
5
  <% module_namespacing do -%>
6
6
  class <%= controller_class_name %>Controller < ApplicationController
7
- before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
7
+ before_action do
8
+ authenticate_user!
9
+ # load_and_authorize_if_present :company do
10
+ load_and_authorize :<%= singular_table_name %>
11
+ # end
12
+ end
8
13
 
9
14
  def index
10
- @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
11
15
  end
12
16
 
13
17
  def show
14
18
  end
15
19
 
16
20
  def new
17
- @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
18
21
  end
19
22
 
20
23
  def edit
@@ -45,11 +48,6 @@ class <%= controller_class_name %>Controller < ApplicationController
45
48
 
46
49
  private
47
50
 
48
- # Use callbacks to share common setup or constraints between actions.
49
- def set_<%= singular_table_name %>
50
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
51
- end
52
-
53
51
  # Only allow a trusted parameter "white list" through.
54
52
  def <%= "#{singular_table_name}_params" %>
55
53
  <%- if attributes_names.empty? -%>
@@ -1,18 +1,25 @@
1
1
  # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
2
 
3
3
  <% unless attributes.empty? -%>
4
+ <% if attributes.length > 1 %>
5
+ <% defaults = " <<: *DEFAULTS" -%>
4
6
  DEFAULTS: &DEFAULTS
5
7
  <% attributes[1..-1].each do |attribute| -%>
6
8
  <%= attribute.name %>: <%= attribute.default %>
7
9
  <% end -%>
10
+ <% else -%>
11
+ # DEFAULTS: &DEFAULTS
12
+ # field_1: meme
13
+ <% defaults = " # <<: *DEFAULTS" -%>
14
+ <% end -%>
8
15
 
9
16
  <%= table_name.singularize %>:
10
17
  <%= attributes.first.name %>: <%= table_name.singularize %>
11
- <<: *DEFAULTS
18
+ <%= defaults %>
12
19
 
13
20
  <%= table_name.singularize %>_other:
14
- <%= attributes.first.name %>: <%= table_name.singularize %>_other
15
- <<: *DEFAULTS
21
+ <%= attributes.first.name %>: <%= table_name.singularize %> other
22
+ <%= defaults %>
16
23
  <% else -%>
17
24
  # one:
18
25
  # column: value
@@ -20,4 +27,3 @@ DEFAULTS: &DEFAULTS
20
27
  # two:
21
28
  # column: value
22
29
  <% end -%>
23
-
@@ -2,6 +2,7 @@ require 'rails_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
4
  describe <%= controller_class_name %>Controller do
5
+ fixtures :<%=table_name %>
5
6
  common_lets
6
7
 
7
8
  before :all do
@@ -11,9 +12,6 @@ describe <%= controller_class_name %>Controller do
11
12
  Fracture.define_selector :cancel_edit_<%= file_name %>_link
12
13
  end
13
14
 
14
- # stub strong params
15
- before { allow(controller).to receive(:<%= file_name %>_params).and_return({}) }
16
-
17
15
  context 'not logged in' do
18
16
  before { sign_out :user }
19
17
 
@@ -26,104 +24,194 @@ describe <%= controller_class_name %>Controller do
26
24
  end
27
25
  end
28
26
 
29
- context 'logged in as user' do
30
- before { sign_in user }
27
+ context 'logged in' do
28
+ before do |meta|
29
+ allow(controller).to receive(:<%= file_name %>_params).and_return({}) # strong params
30
+ allow(user).to receive(:role).and_return(meta.metadata[:role]) # setting user role
31
+ allow(request.env['warden']).to receive(:authenticate!) { user } # stubbing authen
32
+ allow(controller).to receive(:current_user) { user } # stubbing current_user
33
+ end
31
34
 
32
35
  <% unless options[:singleton] -%>
33
36
  describe 'GET index' do
34
- before do
35
- <%= file_name %>; <%= file_name %>_other
36
- get :index
37
- end
37
+ before { |meta| get :index, get_nesting(meta) }
38
38
 
39
- it { is_expected.to assign_to(:<%= table_name %>).with_items(<%= file_name %>) }
40
- it { is_expected.to render_template :index }
41
- it { is_expected.to have_only_fractures(:new_<%= file_name %>_link) }
39
+ context 'un-nested' do
40
+ it 'default role', role: :default do
41
+ is_expected.to assign_to(:<%= table_name %>).with_items(<%= file_name %>, <%= file_name %>_other)
42
+ is_expected.to render_template :index
43
+ is_expected.to have_only_fractures(:new_<%= file_name %>_link)
44
+ end
45
+ # context 'nested under company', company_id: :company do
46
+ # it 'default role', role: :default do
47
+ # is_expected.to assign_to(:<%= table_name %>).with_items(<%= file_name %>)
48
+ # is_expected.to assign_to(:company).with_items(company)
49
+ # is_expected.to render_template :index
50
+ # is_expected.to have_only_fractures(:new_<%= file_name %>_link)
51
+ # end
52
+ # end
53
+ end
42
54
  end
43
55
  <% end -%>
44
56
 
45
57
  describe 'GET show' do
46
- before { get :show, id: <%= file_name %> }
58
+ before { |meta| get :show, get_nesting(meta, id: <%= file_name %>) }
47
59
 
48
- it { is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>) }
49
- it { is_expected.to render_template :show }
50
- it { is_expected.to have_only_fractures(:edit_<%= file_name %>_link) }
60
+ context 'un-nested' do
61
+ it 'default role', role: :default do
62
+ is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
63
+ is_expected.to render_template :show
64
+ is_expected.to have_only_fractures(:edit_<%= file_name %>_link)
65
+ end
66
+ # context 'nested under company', company_id: :company do
67
+ # it 'default role', role: :default do
68
+ # is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
69
+ # is_expected.to assign_to(:company).with_items(company)
70
+ # is_expected.to render_template :show
71
+ # is_expected.to have_only_fractures(:edit_<%= file_name %>_link)
72
+ # end
73
+ # end
74
+ end
51
75
  end
52
76
 
53
77
  describe 'GET new' do
54
- before { get :new }
55
-
56
- it { is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>) }
57
- # it { is_expected.to assign_to('<%= file_name %>.parent').with(parent) }
58
- it { is_expected.to render_template :new }
59
- it { is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link }
60
- it { is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path) }
78
+ before { |meta| get :new, get_nesting(meta) }
79
+
80
+ context 'un-nested' do
81
+ it 'default role', role: :default do
82
+ is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>)
83
+ is_expected.to render_template :new
84
+ is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link
85
+ is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path)
86
+ end
87
+ # context 'nested under company', company_id: :company do
88
+ # it 'default role', role: :default do
89
+ # is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>)
90
+ # is_expected.to assign_to(:company).with_items(company)
91
+ # is_expected.to assign_to('<%= file_name %>.parent').with(parent)
92
+ # is_expected.to render_template :new
93
+ # is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link
94
+ # is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path)
95
+ # end
96
+ # end
97
+ end
61
98
  end
62
99
 
63
100
  describe 'POST create' do
64
- context 'valid' do
65
- before do
66
- allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(true)
67
- post :create
68
- end
69
-
70
- it { is_expected.to redirect_to <%= file_name %>_path(<%= class_name %>.last) }
71
- it { is_expected.to assign_to(:<%= file_name %>).with(<%= class_name %>.last) }
72
- # it { is_expected.to assign_to('<%= file_name %>.parent').with(parent) }
101
+ before do |meta|
102
+ allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(meta.metadata[:valid])
103
+ post :create, get_nesting(meta)
73
104
  end
74
105
 
75
- context 'invalid' do
76
- before do
77
- allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(false)
78
- post :create
106
+ context 'un-nested' do
107
+ context 'default role', role: :default do
108
+ it 'valid', valid: true do
109
+ is_expected.to redirect_to <%= file_name %>_path(<%= class_name %>.last)
110
+ is_expected.to assign_to(:<%= file_name %>).with(<%= class_name %>.last)
111
+ end
112
+ it 'invalid', valid: false do
113
+ is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>)
114
+ is_expected.to render_template :new
115
+ is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link
116
+ is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path)
117
+ end
79
118
  end
80
-
81
- it { is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>) }
82
- # it { is_expected.to assign_to('<%= file_name %>.parent').with(parent) }
83
- it { is_expected.to render_template :new }
84
- it { is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link }
85
- it { is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path) }
119
+ # context 'nested under company', company_id: :company do
120
+ # context 'default role', role: :default do
121
+ # it 'valid', valid: true do
122
+ # is_expected.to redirect_to <%= file_name %>_path(<%= class_name %>.last)
123
+ # is_expected.to assign_to(:<%= file_name %>).with(<%= class_name %>.last)
124
+ # is_expected.to assign_to(:company).with_items(company)
125
+ # is_expected.to assign_to('<%= file_name %>.parent').with(parent)
126
+ # end
127
+ # it 'invalid', valid: false do
128
+ # is_expected.to assign_to(:<%= file_name %>).with_kind_of(<%= class_name %>)
129
+ # is_expected.to assign_to('<%= file_name %>.parent').with(parent)
130
+ # is_expected.to assign_to(:company).with_items(company)
131
+ # is_expected.to render_template :new
132
+ # is_expected.to have_only_fractures :cancel_new_<%= file_name %>_link
133
+ # is_expected.to have_a_form.that_is_new.with_path_of(<%= table_name %>_path)
134
+ # end
135
+ # end
136
+ # end
86
137
  end
87
138
  end
88
139
 
89
140
  describe 'GET edit' do
90
- before { get :edit, id: <%= file_name %> }
91
-
92
- it { is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>) }
93
- it { is_expected.to render_template :edit }
94
- it { is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link }
95
- it { is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path) }
141
+ before { |meta| get :edit, get_nesting(meta, id: <%= file_name %>) }
142
+
143
+ context 'un-nested' do
144
+ it 'default role', role: :default do
145
+ is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
146
+ is_expected.to render_template :edit
147
+ is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link
148
+ is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path)
149
+ end
150
+ # context 'nested under company', company_id: :company do
151
+ # it 'default role', role: :default do
152
+ # is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
153
+ # is_expected.to assign_to(:company).with_items(company)
154
+ # is_expected.to render_template :edit
155
+ # is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link
156
+ # is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path)
157
+ # end
158
+ # end
159
+ end
96
160
  end
97
161
 
98
162
  describe 'PUT update' do
99
- context 'valid' do
100
- before do
101
- allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(true)
102
- put :update, id: <%= file_name %>
103
- end
104
-
105
- it { is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>) }
106
- it { is_expected.to redirect_to <%= file_name %>_path(<%= file_name %>) }
163
+ before do |meta|
164
+ allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(meta.metadata[:valid])
165
+ put :update, get_nesting(meta, id: <%= file_name %>)
107
166
  end
108
- context 'invalid' do
109
- before do
110
- <%= file_name %>
111
- allow_any_instance_of(<%= class_name %>).to receive(:valid?).and_return(false)
112
- put :update, id: <%= file_name %>
113
- end
114
167
 
115
- it { is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>) }
116
- it { is_expected.to render_template :edit }
117
- it { is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link }
118
- it { is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path) }
168
+ context 'un-nested' do
169
+ context 'default role', role: :default do
170
+ it 'valid', valid: true do
171
+ is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
172
+ is_expected.to redirect_to <%= file_name %>_path(<%= file_name %>)
173
+ end
174
+ it 'invalid, valid: false' do
175
+ is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
176
+ is_expected.to render_template :edit
177
+ is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link
178
+ is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path)
179
+ end
180
+ end
181
+ # context 'nested under company', company_id: :company do
182
+ # context 'default role', role: :default do
183
+ # it 'valid', valid: true do
184
+ # is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
185
+ # is_expected.to assign_to(:company).with_items(company)
186
+ # is_expected.to redirect_to <%= file_name %>_path(<%= file_name %>)
187
+ # end
188
+ # it 'invalid', valid: false do
189
+ # is_expected.to assign_to(:<%= file_name %>).with(<%= file_name %>)
190
+ # is_expected.to assign_to(:company).with_items(company)
191
+ # is_expected.to render_template :edit
192
+ # is_expected.to have_only_fractures :cancel_edit_<%= file_name %>_link
193
+ # is_expected.to have_a_form.that_is_edit.with_path_of(<%= file_name %>_path)
194
+ # end
195
+ # end
196
+ # end
119
197
  end
120
198
  end
121
199
 
122
200
  describe 'DELETE destroy' do
123
- before { delete :destroy, id: <%= file_name %> }
124
-
125
- it { expect(<%= class_name %>.find_by_id(<%= file_name %>.id)).to be_nil }
126
- it { is_expected.to redirect_to <%= index_helper %>_path }
201
+ before { |meta| delete :destroy, get_nesting(meta, id: <%= file_name %>) }
202
+ context 'un-nested' do
203
+ it 'default role', role: :default do
204
+ expect(<%= class_name %>.find_by_id(<%= file_name %>.id)).to be_nil
205
+ is_expected.to redirect_to <%= index_helper %>_path
206
+ end
207
+ # context 'nested under company', company_id: :company do
208
+ # it 'default role', role: :default do
209
+ # expect(<%= class_name %>.find_by_id(<%= file_name %>.id)).to be_nil
210
+ # is_expected.to assign_to(:company).with_items(company)
211
+ # is_expected.to redirect_to <%= index_helper %>_path
212
+ # end
213
+ # end
214
+ end
127
215
  end
128
216
  end
129
217
  end
@@ -6,6 +6,7 @@ AllCops:
6
6
  - 'db/migrate/*'
7
7
  - '**/db/migrate/*'
8
8
  - 'lib/templates/**/*'
9
+ - 'lib/nested_load_and_authorize.rb'
9
10
  - 'bin/*'
10
11
  RunRailsCops: true
11
12
 
@@ -19,7 +19,7 @@ RSpec.configure do |config|
19
19
  File.truncate(log_file, 0) if File.exist?(log_file)
20
20
 
21
21
  config.include Devise::TestHelpers, type: :controller
22
- config.include FactoryGirl::Syntax::Methods
22
+ # config.include FactoryGirl::Syntax::Methods
23
23
  config.include Capybara::DSL
24
24
  # ## Mock Framework
25
25
  #
@@ -36,7 +36,7 @@ RSpec.configure do |config|
36
36
  # examples within a transaction, remove the following line or assign false
37
37
  # instead of true.
38
38
  config.use_transactional_fixtures = true
39
- config.global_fixtures = :selections
39
+ config.global_fixtures = :selections, :users
40
40
 
41
41
  # If true, the base class of anonymous controllers will be inferred
42
42
  # automatically. This will be the default behavior in future versions of
@@ -0,0 +1,4 @@
1
+ def get_nesting(meta, other_ids = {})
2
+ meta.metadata.select { |k, _| k.to_s.include?('_id') }
3
+ .each_with_object({}) { |(k, v), hsh| hsh[k] = send(v).id }.reverse_merge(other_ids)
4
+ end
@@ -0,0 +1,43 @@
1
+ namespace :test_code do
2
+ unless Rails.env == 'production'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+ # require 'reek/rake/task'
6
+ #
7
+ desc 'Execute Rspec'
8
+ RSpec::Core::RakeTask.new(:spec) do |tsk|
9
+ tsk.rspec_opts = '--format p'
10
+ end
11
+
12
+ desc 'Execute rubocop -DR'
13
+ RuboCop::RakeTask.new(:rubocop) do |tsk|
14
+ tsk.options = ['-DR'] # Rails, display cop name
15
+ tsk.fail_on_error = false
16
+ end
17
+ #
18
+ # desc 'Execute reek'
19
+ # Reek::Rake::Task.new do |tsk|
20
+ # tsk.source_files = ['app/**/*.rb', 'lib/**/*.rb', 'lib/tasks/*.rake', 'config/**/*.rb']
21
+ # tsk.fail_on_error = false
22
+ # # tsk.verbose = true
23
+ # end
24
+ #
25
+ # desc 'Execute haml-lint'
26
+ # task haml_lint: :environment do
27
+ # puts 'HAML-LINT'
28
+ # puts %x(haml-lint .)
29
+ # end
30
+ #
31
+ # desc 'Execute rails_best_practices'
32
+ # task rbp: :environment do
33
+ # require 'rails_best_practices'
34
+ # analyzer = RailsBestPractices::Analyzer.new('.')
35
+ # analyzer.analyze
36
+ # puts analyzer.output
37
+ # end
38
+ end
39
+ end
40
+
41
+ task :testcode do
42
+ %w(rubocop haml_lint reek rbp spec).each { |task| Rake::Task["testcode:#{task}"].invoke }
43
+ end
@@ -1,3 +1,3 @@
1
1
  module Kitestrings
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitestrings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ridge
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-02-11 00:00:00.000000000 Z
14
+ date: 2015-02-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -143,6 +143,7 @@ files:
143
143
  - lib/generators/templates/haml/scaffold/index.html.haml
144
144
  - lib/generators/templates/haml/scaffold/new.html.haml
145
145
  - lib/generators/templates/haml/scaffold/show.html.haml
146
+ - lib/generators/templates/lib/nested_load_and_authorize.rb
146
147
  - lib/generators/templates/rails/scaffold_controller/controller.rb
147
148
  - lib/generators/templates/rspec/helper/helper_spec.rb
148
149
  - lib/generators/templates/rspec/integration/request_spec.rb
@@ -157,7 +158,9 @@ files:
157
158
  - lib/generators/templates/support/common_lets.rb
158
159
  - lib/generators/templates/support/database_cleaner.rb
159
160
  - lib/generators/templates/support/fracture.rb
161
+ - lib/generators/templates/support/get_nesting.rb
160
162
  - lib/generators/templates/support/render_views.rb
163
+ - lib/generators/templates/tasks/test_code.rake
161
164
  - lib/generators/templates/views/application/_navigation.html.haml
162
165
  - lib/generators/templates/views/layouts/application.html.haml
163
166
  - lib/generators/templates/views/public/403.html