lazy-head-gen 0.5.1 → 0.6.0

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.
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # lazy-head-gen
2
2
 
3
- lazy-head-gen provides some extra generators for the [Padrino](https://github.com/padrino/padrino-framework) framework.
3
+ lazy-head-gen provides some extra generators for the
4
+ [Padrino](https://github.com/padrino/padrino-framework) framework.
4
5
 
5
- The generators are hard wired to use ActiveRecord and MiniTest, as that is the options I normally use in development at [Head](http://www.headlondon.com).
6
+ The generators are hard wired to use ActiveRecord and MiniTest,
7
+ as these are the libraries we normally use in development at
8
+ [Head](http://www.headlondon.com).
6
9
 
7
10
  ## Installation
8
11
 
@@ -17,7 +20,8 @@ gem 'lazy-head-gen', :group => [:development, :test]
17
20
  ```
18
21
 
19
22
  Padrino gotcha: You'll need to put the `gem 'lazy-head-gen'` requirement *after* `gem 'padrino'` in your Gemfile.
20
- lazy-head-gen depends on Padrino being loaded before it can do it's stuff.
23
+
24
+ lazy-head-gen depends on Padrino being loaded before it can do its stuff.
21
25
 
22
26
  Also you will need to add this gem for both :development and :test groups in your Gemfile. There are a few bundled test helper functions and assertions which are used by the test files that are generated.
23
27
 
@@ -73,25 +77,59 @@ padrino g scaffold Product title:string summary:text quantity:integer available_
73
77
 
74
78
  ## Tests
75
79
 
76
- ### Built in assertions and test helpers
77
-
78
80
  First off you will need to add this line to your test_config.rb file, after you have required boot.rb.
79
81
 
80
82
  ```
81
83
  include LazyHeadGen
82
84
  ```
83
85
 
84
- This will allow you to access the couple of test helpers that are used in the generated tests.
86
+ This will allow you to access the `login_as` and `assert_admin_not_logged_in` methods used in the admin generated tests.
87
+
88
+ __login_as__
85
89
 
86
- TODO: list test helper methods.
90
+ ```
91
+ def login_as(account, password = "password", path = "/admin/sessions/create")
92
+ post path, {
93
+ :email => account.email, :password => password
94
+ }
95
+ follow_redirect!
96
+ end
97
+
98
+ alias :login_as_admin :login_as
99
+ ```
100
+
101
+ This is also aliased as `login_as_admin` to avoid breaking any previously generated tests.
102
+
103
+ __assert_admin_not_logged_in__
104
+
105
+ ```
106
+ def assert_admin_not_logged_in
107
+ assert !last_response.ok?
108
+ assert_equal 302, last_response.status
109
+ assert_equal "http://example.org/admin/sessions/new", last_response.original_headers["Location"]
110
+ end
111
+ ```
87
112
 
88
113
  ### blueprints.rb
89
114
 
90
- The scaffold and admin_controller_test generators are reliant on you using a blueprints.rb file.
115
+ The scaffold and admin_controller_test generators are reliant on you using a
116
+ machinist blueprints.rb file.
117
+
118
+ ## Changelog
119
+
120
+ 0.6.X - Removed admin_url helper as it wasn't really needed. If you are using this in your tests you should change them to Admin.url (standard Padrino way of accessing URL's).
121
+
122
+ Also the syntax was incorrect for :create and :update URL's where the object had been put in the admin_url call. IE admin_url(:books, :create, :book => Book.make.attributes) should change to Admin.url(:books, :create), :book => Book.make.attributes
123
+
124
+ Changed login_as_admin to login_as, although is aliased so shouldn't break any previous tests.
125
+
126
+ 0.5.X - Removed the shorthands for path, status etc because they
127
+ weren't namespaced so they confliced with other tests and properties of objects...not good.
128
+
129
+ If you have been using them in your projects you will need to change them to the regular variables, ie `last_response.status` etc.
91
130
 
92
131
  ## To Do List
93
132
 
94
- * Finish README - Built in assertions and test helpers
95
133
  * Add form output to the scaffold generator
96
134
  * Add documentation for testing gem dependencies
97
135
 
@@ -107,5 +145,6 @@ The scaffold and admin_controller_test generators are reliant on you using a blu
107
145
 
108
146
  ## Copyright
109
147
 
110
- Copyright (c) 2012 [Stuart Chinery](http://www.headlondon.com/who-we-are#stuart-chinery), [headlondon.com](http://www.headlondon.com)
148
+ Copyright (c) 2012 [Stuart Chinery](http://www.headlondon.com/who-we-are#stuart-chinery) and [Dave Hrycyszyn](http://www.headlondon.com/who-we-are#david-hrycyszyn) - [headlondon.com](http://www.headlondon.com)
149
+
111
150
  See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{Some extra generators for Padrino, using ActiveRecord and MiniTest.}
21
21
  gem.description = %Q{lazy-head-gen adds some extra generators to Padrino. Currently they are hard wired to use ActiveRecord and MiniTest.}
22
22
  gem.email = "stuart.chinery@headlondon.com"
23
- gem.authors = ["Stuart Chinery"]
23
+ gem.authors = ["Stuart Chinery", "Dave Hrycyszyn"]
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lazy-head-gen"
8
- s.version = "0.5.1"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Stuart Chinery"]
12
- s.date = "2012-07-25"
11
+ s.authors = ["Stuart Chinery", "Dave Hrycyszyn"]
12
+ s.date = "2012-10-05"
13
13
  s.description = "lazy-head-gen adds some extra generators to Padrino. Currently they are hard wired to use ActiveRecord and MiniTest."
14
14
  s.email = "stuart.chinery@headlondon.com"
15
15
  s.extra_rdoc_files = [
@@ -1,54 +1,29 @@
1
1
  begin
2
2
  require 'padrino-gen'
3
- Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{bootstrapped_admin_app,admin_controller_test,scaffold}.rb']
3
+ Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/lazy-head-gen/{admin_controller_test,scaffold}.rb']
4
4
  rescue LoadError
5
5
  # Fail silently
6
6
  end
7
7
 
8
8
  module LazyHeadGen
9
-
10
9
  # Allows testing as a logged in admin user
11
10
  #
12
11
  # param [Account] account - The account to attempt login with
13
- def login_as_admin(account)
14
- post "/admin/sessions/create", {
15
- :email => account.email, :password => "password"
12
+ def login_as(account, password = "password", path = "/admin/sessions/create")
13
+ post path, {
14
+ :email => account.email, :password => password
16
15
  }
17
16
  follow_redirect!
18
17
  end
19
18
 
19
+ alias :login_as_admin :login_as
20
+
20
21
  # Standard assertions to test when an admin user is not logged in
21
22
  # and trys to view an admin page
22
23
  #
23
24
  def assert_admin_not_logged_in
24
25
  assert !last_response.ok?
25
26
  assert_equal 302, last_response.status
26
- assert_equal "http://example.org/admin/sessions/new", last_response.original_headers["Location"]
27
+ assert last_response.original_headers["Location"].include?(Admin.url(:sessions, :new))
27
28
  end
28
-
29
- # Removing due to conflicts when testing.
30
- #
31
- # def path
32
- # last_request.path
33
- # end
34
-
35
- # def session
36
- # last_request.env['rack.session']
37
- # end
38
-
39
- # def body
40
- # last_response.body
41
- # end
42
-
43
- # def status
44
- # last_response.status
45
- # end
46
-
47
- # def location
48
- # last_response.original_headers["Location"]
49
- # end
50
-
51
- # def ok?
52
- # last_response.ok?
53
- # end
54
29
  end
@@ -2,17 +2,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_config.rb')
2
2
 
3
3
  describe "Admin::<%= @controller if @controller %>Controller" do
4
4
 
5
- # START NOT LOGGED IN
6
- describe "when not logged in" do
5
+ # START LOGGED IN
6
+ describe "when logged in" do
7
+ before do
8
+ @account = Account.make!
9
+ login_as(@account)
10
+ end
7
11
 
8
12
  # START GET index
9
13
  describe "GET index" do
10
14
  before do
11
- get "/admin/<%= @pluralized %>"
15
+ get Admin.url(:<%= @pluralized %>, :index)
12
16
  end
13
17
 
14
- it "should not display the <%= @pluralized %> index page" do
15
- assert_admin_not_logged_in
18
+ it "should display the <%= @pluralized %> index page" do
19
+ assert_equal 200, last_response.status
20
+ assert_equal Admin.url(:<%= @pluralized %>, :index), last_request.path
16
21
  end
17
22
  end
18
23
  # END GET index
@@ -20,24 +25,30 @@ describe "Admin::<%= @controller if @controller %>Controller" do
20
25
  # START GET new
21
26
  describe "GET new" do
22
27
  before do
23
- get "/admin/<%= @pluralized %>/new"
28
+ get Admin.url(:<%= @pluralized %>, :new)
24
29
  end
25
30
 
26
- it "should not display the <%= @pluralized %> new page" do
27
- assert_admin_not_logged_in
31
+ it "should display the <%= @pluralized %> new page" do
32
+ assert_equal 200, last_response.status
33
+ assert_equal Admin.url(:<%= @pluralized %>, :new), last_request.path
28
34
  end
29
35
  end
30
36
  # END GET new
31
37
 
32
38
  # START POST create
33
- describe "Post create" do
39
+ describe "POST create" do
34
40
  before do
35
- post "/admin/<%= @pluralized %>/create",
36
- :<%= @singular %> => <%= @model %>.make.attributes
41
+ @<%= @singular %>_count = <%= @model %>.count
42
+ post Admin.url(:<%= @pluralized %>, :create), :<%= @singular %> => <%= @model %>.make.attributes
43
+ follow_redirect!
37
44
  end
38
45
 
39
- it "should not return the created text" do
40
- assert_admin_not_logged_in
46
+ it "should redirect to the edit page" do
47
+ assert_equal Admin.url(:<%= @pluralized %>, :edit, :id => <%= @model %>.last.to_param), last_request.path
48
+ end
49
+
50
+ it "should create a <%= @singular %>" do
51
+ assert_equal @<%= @singular %>_count + 1, <%= @model %>.count
41
52
  end
42
53
  end
43
54
  # END POST create
@@ -46,12 +57,12 @@ describe "Admin::<%= @controller if @controller %>Controller" do
46
57
  describe "GET edit" do
47
58
  before do
48
59
  @<%= @singular %> = <%= @model %>.make!
49
-
50
- get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}"
60
+ get Admin.url(:<%= @pluralized %>, :edit, :id => @<%= @singular %>.to_param)
51
61
  end
52
62
 
53
- it "should not display the <%= @pluralized %> edit page" do
54
- assert_admin_not_logged_in
63
+ it "should display the <%= @pluralized %> edit page" do
64
+ assert_equal 200, last_response.status
65
+ assert_equal Admin.url(:<%= @pluralized %>, :edit, :id => @<%= @singular %>.to_param), last_request.path
55
66
  end
56
67
  end
57
68
  # END GET edit
@@ -60,51 +71,58 @@ describe "Admin::<%= @controller if @controller %>Controller" do
60
71
  describe "PUT update" do
61
72
  before do
62
73
  @<%= @singular %> = <%= @model %>.make!
74
+ @<%= @singular %>_count = <%= @model %>.count
63
75
 
64
- put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}",
76
+ put Admin.url(:<%= @pluralized %>, :update, :id => @<%= @singular %>.to_param),
65
77
  :<%= @singular %> => <%= @model %>.make.attributes
78
+
79
+ @<%= @singular %>.reload
80
+ follow_redirect!
66
81
  end
67
82
 
68
- it "should not return the updated text" do
69
- assert_admin_not_logged_in
83
+ it "should redirect to the edit page" do
84
+ assert_equal Admin.url(:<%= @pluralized %>, :edit, :id => @<%= @singular %>.to_param), last_request.path
85
+ end
86
+
87
+ it "should not create a new a <%= @singular %>" do
88
+ assert_equal @<%= @singular %>_count, <%= @model %>.count
70
89
  end
71
90
  end
72
91
  # END PUT update
73
92
 
74
93
  # START DELETE destroy
75
- describe "on DELETE destroy" do
94
+ describe "DELETE destroy" do
76
95
  before do
77
96
  @<%= @singular %> = <%= @model %>.make!
97
+ @<%= @singular %>_count = <%= @model %>.count
98
+ delete Admin.url(:<%= @pluralized %>, :destroy, :id => @<%= @singular %>.to_param)
99
+ follow_redirect!
100
+ end
78
101
 
79
- delete "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}"
102
+ it "should redirect to the index page" do
103
+ assert_equal Admin.url(:<%= @pluralized %>, :index), last_request.path
80
104
  end
81
105
 
82
- it "should not return the destroyed text" do
83
- assert_admin_not_logged_in
106
+ it "should destroy a <%= @singular %>" do
107
+ assert_equal @<%= @singular %>_count - 1, <%= @model %>.count
84
108
  end
85
109
  end
86
110
  # END DELETE destroy
87
111
 
88
112
  end
89
- # END NOT LOGGED IN
113
+ # END LOGGED IN
90
114
 
91
- # START LOGGED IN
92
- describe "when logged in" do
93
- before do
94
- @account = Account.make!
95
- login_as_admin(@account)
96
- end
115
+ # START NOT LOGGED IN
116
+ describe "when not logged in" do
97
117
 
98
118
  # START GET index
99
119
  describe "GET index" do
100
120
  before do
101
- get "/admin/<%= @pluralized %>"
121
+ get Admin.url(:<%= @pluralized %>, :index)
102
122
  end
103
123
 
104
- it "should display the <%= @pluralized %> index page" do
105
- assert ok?
106
- assert_equal 200, last_response.status
107
- assert_equal "/admin/<%= @pluralized %>", last_request.path
124
+ it "should not display the <%= @pluralized %> index page" do
125
+ assert_admin_not_logged_in
108
126
  end
109
127
  end
110
128
  # END GET index
@@ -112,32 +130,23 @@ describe "Admin::<%= @controller if @controller %>Controller" do
112
130
  # START GET new
113
131
  describe "GET new" do
114
132
  before do
115
- get "/admin/<%= @pluralized %>/new"
133
+ get Admin.url(:<%= @pluralized %>, :new)
116
134
  end
117
135
 
118
- it "should display the <%= @pluralized %> new page" do
119
- assert ok?
120
- assert_equal 200, last_response.status
121
- assert_equal "/admin/<%= @pluralized %>", last_request.path
136
+ it "should not display the <%= @pluralized %> new page" do
137
+ assert_admin_not_logged_in
122
138
  end
123
139
  end
124
140
  # END GET new
125
141
 
126
142
  # START POST create
127
- describe "POST create" do
143
+ describe "Post create" do
128
144
  before do
129
- @<%= @singular %>_count = <%= @model %>.count
130
-
131
- post "/admin/<%= @pluralized %>/create", :<%= @singular %> => <%= @model %>.make.attributes
145
+ post Admin.url(:<%= @pluralized %>, :create), :<%= @singular %> => <%= @model %>.make.attributes
132
146
  end
133
147
 
134
- it "should redirect to the edit page" do
135
- assert_equal 302, last_response.status
136
- assert location.include?("/admin/<%= @pluralized %>/edit/#{<%= @model %>.last.to_param}")
137
- end
138
-
139
- it "should create a <%= @singular %>" do
140
- assert_equal @<%= @singular %>_count + 1, <%= @model %>.count
148
+ it "should not return the created text" do
149
+ assert_admin_not_logged_in
141
150
  end
142
151
  end
143
152
  # END POST create
@@ -145,14 +154,11 @@ describe "Admin::<%= @controller if @controller %>Controller" do
145
154
  # START GET edit
146
155
  describe "GET edit" do
147
156
  before do
148
- @<%= @singular %> = <%= @model %>.make!
149
- get "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}"
157
+ get Admin.url(:<%= @pluralized %>, :edit, :id => 1)
150
158
  end
151
159
 
152
- it "should display the <%= @pluralized %> edit page" do
153
- assert ok?
154
- assert_equal 200, last_response.status
155
- assert_equal "/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}", last_request.path
160
+ it "should not display the <%= @pluralized %> edit page" do
161
+ assert_admin_not_logged_in
156
162
  end
157
163
  end
158
164
  # END GET edit
@@ -160,45 +166,28 @@ describe "Admin::<%= @controller if @controller %>Controller" do
160
166
  # START PUT update
161
167
  describe "PUT update" do
162
168
  before do
163
- @<%= @singular %> = <%= @model %>.make!
164
- @<%= @singular %>_count = <%= @model %>.count
165
-
166
- put "/admin/<%= @pluralized %>/update/#{@<%= @singular %>.to_param}",
167
- :<%= @singular %> => <%= @model %>.make.attributes
168
-
169
- @<%= @singular %>.reload
169
+ put Admin.url(:<%= @pluralized %>, :update, :id => 1), :<%= @singular %> => <%= @model %>.make.attributes
170
170
  end
171
171
 
172
- it "should redirect to the edit page" do
173
- assert_equal 302, last_response.status
174
- assert location.include?("/admin/<%= @pluralized %>/edit/#{@<%= @singular %>.to_param}")
175
- end
176
-
177
- it "should not create a new a <%= @singular %>" do
178
- assert_equal @<%= @singular %>_count, <%= @model %>.count
172
+ it "should not return the updated text" do
173
+ assert_admin_not_logged_in
179
174
  end
180
175
  end
181
176
  # END PUT update
182
177
 
183
178
  # START DELETE destroy
184
- describe "DELETE destroy" do
179
+ describe "on DELETE destroy" do
185
180
  before do
186
- @<%= @singular %> = <%= @model %>.make!
187
- @<%= @singular %>_count = <%= @model %>.count
188
- delete "/admin/<%= @pluralized %>/destroy/#{@<%= @singular %>.to_param}"
189
- end
190
-
191
- it "should redirect to the index page" do
192
- assert_equal 302, last_response.status
181
+ delete Admin.url(:<%= @pluralized %>, :destroy, :id => 1)
193
182
  end
194
183
 
195
- it "should destroy a <%= @singular %>" do
196
- assert_equal @<%= @singular %>_count - 1, <%= @model %>.count
184
+ it "should not return the destroyed text" do
185
+ assert_admin_not_logged_in
197
186
  end
198
187
  end
199
188
  # END DELETE destroy
200
189
 
201
190
  end
202
- # END LOGGED IN
191
+ # END NOT LOGGED IN
203
192
 
204
193
  end
@@ -9,7 +9,7 @@ describe "<%= @controller if @controller %>Controller" do
9
9
  end
10
10
 
11
11
  it "should display the <%= @pluralized %> index page" do
12
- assert_match "This is the index page", body
12
+ assert_match "This is the index page", last_response.body
13
13
  end
14
14
  end
15
15
  # END GET index
@@ -22,7 +22,7 @@ describe "<%= @controller if @controller %>Controller" do
22
22
  end
23
23
 
24
24
  it "should display the <%= @pluralized %> show page" do
25
- assert_match "This is the show page", body
25
+ assert_match "This is the show page", last_response.body
26
26
  end
27
27
  end
28
28
  # END GET show
@@ -35,7 +35,7 @@ describe "<%= @controller if @controller %>Controller" do
35
35
  end
36
36
 
37
37
  it "should display the <%= @pluralized %> new page" do
38
- assert_match "This is the new page", body
38
+ assert_match "This is the new page", last_response.body
39
39
  end
40
40
  end
41
41
  # END GET new
@@ -49,7 +49,7 @@ describe "<%= @controller if @controller %>Controller" do
49
49
 
50
50
  it "should redirect to the show page" do
51
51
  assert_equal 302, last_response.status
52
- assert location.include?("/<%= @pluralized %>/show/")
52
+ assert last_response.original_headers["Location"].include?("/<%= @pluralized %>/show/")
53
53
  end
54
54
 
55
55
  it "should create a new <%= @singular %>" do
@@ -66,7 +66,7 @@ describe "<%= @controller if @controller %>Controller" do
66
66
  end
67
67
 
68
68
  it "should display the <%= @pluralized %> edit page" do
69
- assert_match "This is the edit page", body
69
+ assert_match "This is the edit page", last_response.body
70
70
  end
71
71
  end
72
72
  # END GET edit
@@ -82,7 +82,7 @@ describe "<%= @controller if @controller %>Controller" do
82
82
 
83
83
  it "should redirect to the show page" do
84
84
  assert_equal 302, last_response.status
85
- assert location.include?("/<%= @pluralized %>/show/")
85
+ assert last_response.original_headers["Location"].include?("/<%= @pluralized %>/show/")
86
86
  end
87
87
 
88
88
  it "should not create a new <%= @singular %>" do
@@ -15,7 +15,7 @@ require 'uuid'
15
15
  require 'thor/group'
16
16
  require 'padrino-core/support_lite' unless defined?(SupportLite)
17
17
  require 'padrino-admin'
18
- require File.dirname(__FILE__) + '/../lib/lazy-head-gen.rb'
18
+ require 'lazy-head-gen'
19
19
 
20
20
  begin; require 'turn/autorun'; rescue LoadError; end
21
21
 
@@ -30,11 +30,6 @@ module Kernel
30
30
  end
31
31
  end
32
32
 
33
- #class Class
34
- # # Allow assertions in request context
35
- # include MiniTest::Assertions
36
- #end
37
-
38
33
  class MiniTest::Unit::TestCase
39
34
  # Sets up a Sinatra::Base subclass defined with the block
40
35
  # given. Used in setup or individual spec methods to establish
@@ -82,15 +77,4 @@ class MiniTest::Unit::TestCase
82
77
  def assert_no_match_in_file(pattern, file)
83
78
  File.exists?(file) ? refute_match(pattern, File.read(file)) : assert_file_exists(file)
84
79
  end
85
-
86
- # Delegate other missing methods to response.
87
- # def method_missing(name, *args, &block)
88
- # if response && response.respond_to?(name)
89
- # response.send(name, *args, &block)
90
- # else
91
- # super(name, *args, &block)
92
- # end
93
- # end
94
-
95
- # alias :response :last_response
96
80
  end
metadata CHANGED
@@ -1,21 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy-head-gen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stuart Chinery
14
+ - Dave Hrycyszyn
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2012-07-25 00:00:00 Z
19
+ date: 2012-10-05 00:00:00 Z
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  type: :runtime