genderize 0.0.3 → 0.0.4

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: f590ec5a9831dd9016d6b09cca52d9b7b3f61953
4
- data.tar.gz: f5173c96546200eb7eb22277c19afc4d43878cdd
3
+ metadata.gz: afc7dc1238ac032292575d60a4c79adc808085c8
4
+ data.tar.gz: 063d04610f846338044372cc9bfdbf4b27ba7ac3
5
5
  SHA512:
6
- metadata.gz: da8cf63be0f3e3c1e756a8e02e8144f6c7806a4b05ec6c60436d43e71a6262129aee4f7cda4d155181d6abdf4ab0b5b9cac134304e0578d1171cbe9ab1b37c53
7
- data.tar.gz: 5b9ae766aa1e2fae6679da160a112a0e655a2c57e38982c9068d3c62e827dca04a6e7b957d908f1b297cfab2c30e46f1d3e8db1a05e22b30408153d391dea8dd
6
+ metadata.gz: 9aef209153896d7aea632cc1d05146f7c42cac3b1f792faa6bdd8d0dc370ff4a944a315cc57c9f5d3f03bfd99a0bd5d8dd6cb8870e45d14428fd61f35474db32
7
+ data.tar.gz: 9f1f7ce7ac8ad56eb8c36edcf0fa7d410d3d86bfc2e3aec91e60c5b3146dff3dcdfae835fa0c003b29f63815d7c1ad07c729a665ac3a366c1137337c9a080c94
data/lib/genderize.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "genderize/genderize"
1
+ require "genderize/gender"
2
2
  require "genderize/engine"
3
3
 
4
4
  unless Rails
@@ -6,4 +6,53 @@ unless Rails
6
6
  end
7
7
 
8
8
  module Genderize
9
+
10
+ def self.included(base)
11
+ base.extend(ClassMethods)
12
+ end
13
+
14
+ module ClassMethods
15
+
16
+
17
+ def genderize(col_name = "gender")
18
+ # Reads the DB column value for gender attribute and creates a new Gender
19
+ # object with it's value
20
+ #
21
+ # The object is memoized for future calls.
22
+ #
23
+ # Returns a Gender
24
+ define_method col_name do
25
+ if value = instance_variable_get("@#{col_name}")
26
+ return value
27
+ end
28
+ read_value = read_attribute(col_name)
29
+ if read_value.blank?
30
+ return read_value
31
+ else
32
+ instance_variable_set("@#{col_name}", Genderize::Gender.new(read_attribute(col_name)))
33
+ end
34
+ end
35
+
36
+ # Writes to the DB column the new value for the gender attribute
37
+ # Sets the instance varaible value too
38
+ #
39
+ # string - A String indicating the gender. Must be either 'm', "M", 'f' or "F".
40
+ #
41
+ # Raises ArgumentError if gender is not a single alphanumeric character "m" or "f"
42
+ define_method "#{col_name}=" do |string|
43
+ unless string.blank? or string.to_s =~ /\A(m|f)\Z/i
44
+ raise ArgumentError, "Gender must be a single alphanumeric character"
45
+ end
46
+ write_attribute(col_name, string)
47
+
48
+ if string.blank?
49
+ instance_variable_set("@#{col_name}", string)
50
+ else
51
+ instance_variable_set("@#{col_name}", Genderize::Gender.new(read_attribute(col_name)))
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
9
58
  end
@@ -1,7 +1,6 @@
1
1
  module Genderize
2
2
  class Engine < ::Rails::Engine
3
- isolate_namespace Genderize
4
-
3
+
5
4
  initializer "genderize.extend_active_record" do
6
5
 
7
6
  if defined?(::ActiveRecord::Base)
@@ -1,3 +1,3 @@
1
1
  module Genderize
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,83 @@
1
+ class UsersController < ActionController::Base
2
+ # GET /users
3
+ # GET /users.json
4
+ def index
5
+ @users = User.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @users }
10
+ end
11
+ end
12
+
13
+ # GET /users/1
14
+ # GET /users/1.json
15
+ def show
16
+ @user = User.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @user }
21
+ end
22
+ end
23
+
24
+ # GET /users/new
25
+ # GET /users/new.json
26
+ def new
27
+ @user = User.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @user }
32
+ end
33
+ end
34
+
35
+ # GET /users/1/edit
36
+ def edit
37
+ @user = User.find(params[:id])
38
+ end
39
+
40
+ # POST /users
41
+ # POST /users.json
42
+ def create
43
+ @user = User.new(params[:user])
44
+
45
+ respond_to do |format|
46
+ if @user.save
47
+ format.html { redirect_to @user, notice: 'User was successfully created.' }
48
+ format.json { render json: @user, status: :created, location: @user }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @user.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /users/1
57
+ # PUT /users/1.json
58
+ def update
59
+ @user = User.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @user.update_attributes(params[:user])
63
+ format.html { redirect_to @user, notice: 'User was successfully updated.' }
64
+ format.json { head :no_content }
65
+ else
66
+ format.html { render action: "edit" }
67
+ format.json { render json: @user.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /users/1
73
+ # DELETE /users/1.json
74
+ def destroy
75
+ @user = User.find(params[:id])
76
+ @user.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to users_url }
80
+ format.json { head :no_content }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,27 @@
1
+ <%= form_for(@user) do |f| %>
2
+ <% if @user.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @user.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %><br />
16
+ <%= f.text_field :name %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= f.label :gender %><br />
21
+ <%= f.text_field :gender %>
22
+ </div>
23
+
24
+ <div class="actions">
25
+ <%= f.submit %>
26
+ </div>
27
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing user</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @user %> |
6
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,32 @@
1
+ <h1>Listing users</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Gender</th>
7
+ <th>Abbr</th>
8
+ <th>Subject</th>
9
+ <th>Object</th>
10
+ <th>Casual</th>
11
+ </tr>
12
+
13
+ <% @users.each do |user| %>
14
+ <tr>
15
+ <td><%= user.name %></td>
16
+ <td><%= user.gender %></td>
17
+
18
+ <td><%= user.gender.abbr %></td>
19
+ <td><%= user.gender.subject %></td>
20
+ <td><%= user.gender.object %></td>
21
+ <td><%= user.gender.casual %></td>
22
+
23
+ <td><%= link_to 'Show', user %></td>
24
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
25
+ <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
26
+ </tr>
27
+ <% end %>
28
+ </table>
29
+
30
+ <br />
31
+
32
+ <%= link_to 'New User', new_user_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New user</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', users_path %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @user.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Gender:</b>
10
+ <%= @user.gender %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_user_path(@user) %> |
14
+ <%= link_to 'Back', users_path %>
@@ -1,4 +1,4 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
- mount Genderize::Engine => "/genderize"
3
+ resources :users
4
4
  end
Binary file
@@ -67,3 +67,255 @@ Connecting to database specified by database.yml
67
67
   (3.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
68
68
   (0.1ms) SELECT version FROM "schema_migrations"
69
69
   (3.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20130506080641')
70
+ Connecting to database specified by database.yml
71
+
72
+
73
+ Started GET "/" for 127.0.0.1 at 2013-05-06 17:43:04 +0100
74
+
75
+ ActionController::RoutingError (No route matches [GET] "/"):
76
+ actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
77
+ actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
78
+ railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
79
+ railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
80
+ activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
81
+ railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
82
+ actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
83
+ rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
84
+ rack (1.4.5) lib/rack/runtime.rb:17:in `call'
85
+ activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
86
+ rack (1.4.5) lib/rack/lock.rb:15:in `call'
87
+ actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
88
+ railties (3.2.13) lib/rails/engine.rb:479:in `call'
89
+ railties (3.2.13) lib/rails/application.rb:223:in `call'
90
+ rack (1.4.5) lib/rack/content_length.rb:14:in `call'
91
+ railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
92
+ rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
93
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
94
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
95
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
96
+
97
+
98
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (4.6ms)
99
+ Connecting to database specified by database.yml
100
+ Connecting to database specified by database.yml
101
+
102
+
103
+ Started GET "/" for 127.0.0.1 at 2013-05-06 17:54:07 +0100
104
+
105
+ ActionController::RoutingError (No route matches [GET] "/"):
106
+ actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
107
+ actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
108
+ railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app'
109
+ railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call'
110
+ activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged'
111
+ railties (3.2.13) lib/rails/rack/logger.rb:16:in `call'
112
+ actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call'
113
+ rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
114
+ rack (1.4.5) lib/rack/runtime.rb:17:in `call'
115
+ activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
116
+ rack (1.4.5) lib/rack/lock.rb:15:in `call'
117
+ actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call'
118
+ railties (3.2.13) lib/rails/engine.rb:479:in `call'
119
+ railties (3.2.13) lib/rails/application.rb:223:in `call'
120
+ rack (1.4.5) lib/rack/content_length.rb:14:in `call'
121
+ railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call'
122
+ rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
123
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
124
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
125
+ /Users/Gavin/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
126
+
127
+
128
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
129
+ Connecting to database specified by database.yml
130
+ SQLite3::ConstraintException: users.name may not be NULL: INSERT INTO "users" ("created_at", "gender", "name", "updated_at") VALUES (?, ?, ?, ?)
131
+ Connecting to database specified by database.yml
132
+ Connecting to database specified by database.yml
133
+
134
+
135
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 17:57:03 +0100
136
+
137
+ ActionController::RoutingError (uninitialized constant ApplicationController):
138
+ app/controllers/users_controller.rb:1:in `<top (required)>'
139
+
140
+
141
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
142
+
143
+
144
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 17:57:35 +0100
145
+ Processing by UsersController#index as HTML
146
+ User Load (0.1ms) SELECT "users".* FROM "users" 
147
+ Rendered users/index.html.erb (11.1ms)
148
+ Completed 500 Internal Server Error in 36ms
149
+
150
+ ActionView::Template::Error (undefined method `new' for #<User:0x007ff260df8ea0>):
151
+ 12:
152
+ 13: <% @users.each do |user| %>
153
+ 14: <tr>
154
+ 15: <td><%= user.new %></td>
155
+ 16: <td><%= user.index %></td>
156
+ 17: <td><%= user.show %></td>
157
+ 18: <td><%= link_to 'Show', user %></td>
158
+ app/views/users/index.html.erb:15:in `block in _app_views_users_index_html_erb__195431217160685788_70339491875360'
159
+ app/views/users/index.html.erb:13:in `each'
160
+ app/views/users/index.html.erb:13:in `_app_views_users_index_html_erb__195431217160685788_70339491875360'
161
+ app/controllers/users_controller.rb:7:in `index'
162
+
163
+
164
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.7ms)
165
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
166
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (13.4ms)
167
+
168
+
169
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 17:58:29 +0100
170
+ Processing by UsersController#index as HTML
171
+ User Load (0.1ms) SELECT "users".* FROM "users"
172
+ Rendered users/index.html.erb (1.2ms)
173
+ Completed 500 Internal Server Error in 4ms
174
+
175
+ ActionView::Template::Error (undefined method `new' for #<User:0x007ff260c4bc88>):
176
+ 12:
177
+ 13: <% @users.each do |user| %>
178
+ 14: <tr>
179
+ 15: <td><%= user.new %></td>
180
+ 16: <td><%= user.index %></td>
181
+ 17: <td><%= user.show %></td>
182
+ 18: <td><%= link_to 'Show', user %></td>
183
+ app/views/users/index.html.erb:15:in `block in _app_views_users_index_html_erb__195431217160685788_70339491875360'
184
+ app/views/users/index.html.erb:13:in `each'
185
+ app/views/users/index.html.erb:13:in `_app_views_users_index_html_erb__195431217160685788_70339491875360'
186
+ app/controllers/users_controller.rb:7:in `index'
187
+
188
+
189
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
190
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
191
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (6.5ms)
192
+
193
+
194
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 17:58:57 +0100
195
+ Processing by UsersController#index as HTML
196
+ User Load (0.1ms) SELECT "users".* FROM "users" 
197
+ Rendered users/index.html.erb (3.1ms)
198
+ Completed 200 OK in 6ms (Views: 5.0ms | ActiveRecord: 0.1ms)
199
+
200
+
201
+ Started GET "/users/new" for 127.0.0.1 at 2013-05-06 17:59:00 +0100
202
+ Processing by UsersController#new as HTML
203
+ Rendered users/_form.html.erb (7.7ms)
204
+ Rendered users/new.html.erb (88.1ms)
205
+ Completed 200 OK in 91ms (Views: 90.4ms | ActiveRecord: 0.0ms)
206
+
207
+
208
+ Started POST "/users" for 127.0.0.1 at 2013-05-06 17:59:06 +0100
209
+ Processing by UsersController#create as HTML
210
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"ldtoT2Ug+eOtkjnmxRe6R4KpW8S/pmP1lgePwQxUDFg=", "user"=>{"name"=>"m", "gender"=>"f"}, "commit"=>"Create User"}
211
+  (0.1ms) begin transaction
212
+ SQL (3.5ms) INSERT INTO "users" ("created_at", "gender", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Mon, 06 May 2013 16:59:06 UTC +00:00], ["gender", "f"], ["name", "m"], ["updated_at", Mon, 06 May 2013 16:59:06 UTC +00:00]]
213
+  (3.6ms) commit transaction
214
+ Redirected to http://localhost:3000/users/2
215
+ Completed 302 Found in 11ms (ActiveRecord: 7.1ms)
216
+
217
+
218
+ Started GET "/users/2" for 127.0.0.1 at 2013-05-06 17:59:06 +0100
219
+ Processing by UsersController#show as HTML
220
+ Parameters: {"id"=>"2"}
221
+ User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
222
+ Rendered users/show.html.erb (1.5ms)
223
+ Completed 500 Internal Server Error in 5ms
224
+
225
+ ActionView::Template::Error (undefined method `new' for #<User:0x007ff2608fa908>):
226
+ 2:
227
+ 3: <p>
228
+ 4: <b>New:</b>
229
+ 5: <%= @user.new %>
230
+ 6: </p>
231
+ 7:
232
+ 8: <p>
233
+ app/views/users/show.html.erb:5:in `_app_views_users_show_html_erb___3696768098522740839_70339489415300'
234
+ app/controllers/users_controller.rb:18:in `show'
235
+
236
+
237
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
238
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
239
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (5.9ms)
240
+
241
+
242
+ Started GET "/users/2" for 127.0.0.1 at 2013-05-06 17:59:28 +0100
243
+ Processing by UsersController#show as HTML
244
+ Parameters: {"id"=>"2"}
245
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
246
+ Rendered users/show.html.erb (1.3ms)
247
+ Completed 200 OK in 6ms (Views: 4.4ms | ActiveRecord: 0.1ms)
248
+
249
+
250
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 17:59:29 +0100
251
+ Processing by UsersController#index as HTML
252
+ User Load (0.2ms) SELECT "users".* FROM "users" 
253
+ Rendered users/index.html.erb (2.0ms)
254
+ Completed 200 OK in 5ms (Views: 3.7ms | ActiveRecord: 0.2ms)
255
+
256
+
257
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 18:01:02 +0100
258
+ Processing by UsersController#index as HTML
259
+ User Load (0.2ms) SELECT "users".* FROM "users"
260
+ Rendered users/index.html.erb (1.9ms)
261
+ Completed 500 Internal Server Error in 6ms
262
+
263
+ ActionView::Template::Error (undefined method `abbr' for #<User:0x007ff2606e2008>):
264
+ 15: <td><%= user.name %></td>
265
+ 16: <td><%= user.gender %></td>
266
+ 17:
267
+ 18: <td><%= user.abbr %></td>
268
+ 19: <td><%= user.subject %></td>
269
+ 20: <td><%= user.object %></td>
270
+ 21: <td><%= user.casual %></td>
271
+ app/views/users/index.html.erb:18:in `block in _app_views_users_index_html_erb__195431217160685788_70339488305400'
272
+ app/views/users/index.html.erb:13:in `each'
273
+ app/views/users/index.html.erb:13:in `_app_views_users_index_html_erb__195431217160685788_70339488305400'
274
+ app/controllers/users_controller.rb:7:in `index'
275
+
276
+
277
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
278
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
279
+ Rendered /Users/Gavin/.rvm/gems/ruby-2.0.0-p0@genderize/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (7.9ms)
280
+
281
+
282
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 18:01:08 +0100
283
+ Processing by UsersController#index as HTML
284
+ User Load (0.2ms) SELECT "users".* FROM "users" 
285
+ Rendered users/index.html.erb (2.8ms)
286
+ Completed 200 OK in 7ms (Views: 5.6ms | ActiveRecord: 0.2ms)
287
+
288
+
289
+ Started GET "/users/2/edit" for 127.0.0.1 at 2013-05-06 18:01:12 +0100
290
+ Processing by UsersController#edit as HTML
291
+ Parameters: {"id"=>"2"}
292
+ User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
293
+ Rendered users/_form.html.erb (2.4ms)
294
+ Rendered users/edit.html.erb (4.4ms)
295
+ Completed 200 OK in 9ms (Views: 7.4ms | ActiveRecord: 0.2ms)
296
+
297
+
298
+ Started PUT "/users/2" for 127.0.0.1 at 2013-05-06 18:01:15 +0100
299
+ Processing by UsersController#update as HTML
300
+ Parameters: {"utf8"=>"✓", "authenticity_token"=>"ldtoT2Ug+eOtkjnmxRe6R4KpW8S/pmP1lgePwQxUDFg=", "user"=>{"name"=>"m", "gender"=>"m"}, "commit"=>"Update User", "id"=>"2"}
301
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
302
+  (0.0ms) begin transaction
303
+  (0.9ms) UPDATE "users" SET "gender" = 'm', "updated_at" = '2013-05-06 17:01:15.759258' WHERE "users"."id" = 2
304
+  (56.4ms) commit transaction
305
+ Redirected to http://localhost:3000/users/2
306
+ Completed 302 Found in 62ms (ActiveRecord: 57.5ms)
307
+
308
+
309
+ Started GET "/users/2" for 127.0.0.1 at 2013-05-06 18:01:15 +0100
310
+ Processing by UsersController#show as HTML
311
+ Parameters: {"id"=>"2"}
312
+ User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", "2"]]
313
+ Rendered users/show.html.erb (0.6ms)
314
+ Completed 200 OK in 3ms (Views: 2.0ms | ActiveRecord: 0.1ms)
315
+
316
+
317
+ Started GET "/users" for 127.0.0.1 at 2013-05-06 18:01:19 +0100
318
+ Processing by UsersController#index as HTML
319
+ User Load (0.1ms) SELECT "users".* FROM "users"
320
+ Rendered users/index.html.erb (1.8ms)
321
+ Completed 200 OK in 4ms (Views: 3.0ms | ActiveRecord: 0.1ms)
@@ -0,0 +1,160 @@
1
+ require 'spec_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+
21
+ describe UsersController do
22
+
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # User. As you add validations to User, be sure to
25
+ # adjust the attributes here as well.
26
+ let(:valid_attributes) { { "new" => "MyString" } }
27
+
28
+ # This should return the minimal set of values that should be in the session
29
+ # in order to pass any filters (e.g. authentication) defined in
30
+ # UsersController. Be sure to keep this updated too.
31
+ let(:valid_session) { {} }
32
+
33
+ describe "GET index" do
34
+ it "assigns all users as @users" do
35
+ user = User.create! valid_attributes
36
+ get :index, {}, valid_session
37
+ assigns(:users).should eq([user])
38
+ end
39
+ end
40
+
41
+ describe "GET show" do
42
+ it "assigns the requested user as @user" do
43
+ user = User.create! valid_attributes
44
+ get :show, {:id => user.to_param}, valid_session
45
+ assigns(:user).should eq(user)
46
+ end
47
+ end
48
+
49
+ describe "GET new" do
50
+ it "assigns a new user as @user" do
51
+ get :new, {}, valid_session
52
+ assigns(:user).should be_a_new(User)
53
+ end
54
+ end
55
+
56
+ describe "GET edit" do
57
+ it "assigns the requested user as @user" do
58
+ user = User.create! valid_attributes
59
+ get :edit, {:id => user.to_param}, valid_session
60
+ assigns(:user).should eq(user)
61
+ end
62
+ end
63
+
64
+ describe "POST create" do
65
+ describe "with valid params" do
66
+ it "creates a new User" do
67
+ expect {
68
+ post :create, {:user => valid_attributes}, valid_session
69
+ }.to change(User, :count).by(1)
70
+ end
71
+
72
+ it "assigns a newly created user as @user" do
73
+ post :create, {:user => valid_attributes}, valid_session
74
+ assigns(:user).should be_a(User)
75
+ assigns(:user).should be_persisted
76
+ end
77
+
78
+ it "redirects to the created user" do
79
+ post :create, {:user => valid_attributes}, valid_session
80
+ response.should redirect_to(User.last)
81
+ end
82
+ end
83
+
84
+ describe "with invalid params" do
85
+ it "assigns a newly created but unsaved user as @user" do
86
+ # Trigger the behavior that occurs when invalid params are submitted
87
+ User.any_instance.stub(:save).and_return(false)
88
+ post :create, {:user => { "new" => "invalid value" }}, valid_session
89
+ assigns(:user).should be_a_new(User)
90
+ end
91
+
92
+ it "re-renders the 'new' template" do
93
+ # Trigger the behavior that occurs when invalid params are submitted
94
+ User.any_instance.stub(:save).and_return(false)
95
+ post :create, {:user => { "new" => "invalid value" }}, valid_session
96
+ response.should render_template("new")
97
+ end
98
+ end
99
+ end
100
+
101
+ describe "PUT update" do
102
+ describe "with valid params" do
103
+ it "updates the requested user" do
104
+ user = User.create! valid_attributes
105
+ # Assuming there are no other users in the database, this
106
+ # specifies that the User created on the previous line
107
+ # receives the :update_attributes message with whatever params are
108
+ # submitted in the request.
109
+ User.any_instance.should_receive(:update_attributes).with({ "new" => "MyString" })
110
+ put :update, {:id => user.to_param, :user => { "new" => "MyString" }}, valid_session
111
+ end
112
+
113
+ it "assigns the requested user as @user" do
114
+ user = User.create! valid_attributes
115
+ put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
116
+ assigns(:user).should eq(user)
117
+ end
118
+
119
+ it "redirects to the user" do
120
+ user = User.create! valid_attributes
121
+ put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
122
+ response.should redirect_to(user)
123
+ end
124
+ end
125
+
126
+ describe "with invalid params" do
127
+ it "assigns the user as @user" do
128
+ user = User.create! valid_attributes
129
+ # Trigger the behavior that occurs when invalid params are submitted
130
+ User.any_instance.stub(:save).and_return(false)
131
+ put :update, {:id => user.to_param, :user => { "new" => "invalid value" }}, valid_session
132
+ assigns(:user).should eq(user)
133
+ end
134
+
135
+ it "re-renders the 'edit' template" do
136
+ user = User.create! valid_attributes
137
+ # Trigger the behavior that occurs when invalid params are submitted
138
+ User.any_instance.stub(:save).and_return(false)
139
+ put :update, {:id => user.to_param, :user => { "new" => "invalid value" }}, valid_session
140
+ response.should render_template("edit")
141
+ end
142
+ end
143
+ end
144
+
145
+ describe "DELETE destroy" do
146
+ it "destroys the requested user" do
147
+ user = User.create! valid_attributes
148
+ expect {
149
+ delete :destroy, {:id => user.to_param}, valid_session
150
+ }.to change(User, :count).by(-1)
151
+ end
152
+
153
+ it "redirects to the users list" do
154
+ user = User.create! valid_attributes
155
+ delete :destroy, {:id => user.to_param}, valid_session
156
+ response.should redirect_to(users_url)
157
+ end
158
+ end
159
+
160
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs in this file have access to a helper object that includes
4
+ # the UsersHelper. For example:
5
+ #
6
+ # describe UsersHelper do
7
+ # describe "string concat" do
8
+ # it "concats two strings with spaces" do
9
+ # helper.concat_strings("this","that").should == "this that"
10
+ # end
11
+ # end
12
+ # end
13
+ describe UsersHelper do
14
+ pending "add some examples to (or delete) #{__FILE__}"
15
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Users" do
4
+ describe "GET /users" do
5
+ it "works! (now write some real specs)" do
6
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
7
+ get users_path
8
+ response.status.should be(200)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe UsersController do
4
+ describe "routing" do
5
+
6
+ it "routes to #index" do
7
+ get("/users").should route_to("users#index")
8
+ end
9
+
10
+ it "routes to #new" do
11
+ get("/users/new").should route_to("users#new")
12
+ end
13
+
14
+ it "routes to #show" do
15
+ get("/users/1").should route_to("users#show", :id => "1")
16
+ end
17
+
18
+ it "routes to #edit" do
19
+ get("/users/1/edit").should route_to("users#edit", :id => "1")
20
+ end
21
+
22
+ it "routes to #create" do
23
+ post("/users").should route_to("users#create")
24
+ end
25
+
26
+ it "routes to #update" do
27
+ put("/users/1").should route_to("users#update", :id => "1")
28
+ end
29
+
30
+ it "routes to #destroy" do
31
+ delete("/users/1").should route_to("users#destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "users/edit" do
4
+ before(:each) do
5
+ @user = assign(:user, stub_model(User,
6
+ :new => "MyString",
7
+ :index => "MyString",
8
+ :show => "MyString"
9
+ ))
10
+ end
11
+
12
+ it "renders the edit user form" do
13
+ render
14
+
15
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
16
+ assert_select "form[action=?][method=?]", user_path(@user), "post" do
17
+ assert_select "input#user_new[name=?]", "user[new]"
18
+ assert_select "input#user_index[name=?]", "user[index]"
19
+ assert_select "input#user_show[name=?]", "user[show]"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe "users/index" do
4
+ before(:each) do
5
+ assign(:users, [
6
+ stub_model(User,
7
+ :new => "New",
8
+ :index => "Index",
9
+ :show => "Show"
10
+ ),
11
+ stub_model(User,
12
+ :new => "New",
13
+ :index => "Index",
14
+ :show => "Show"
15
+ )
16
+ ])
17
+ end
18
+
19
+ it "renders a list of users" do
20
+ render
21
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
22
+ assert_select "tr>td", :text => "New".to_s, :count => 2
23
+ assert_select "tr>td", :text => "Index".to_s, :count => 2
24
+ assert_select "tr>td", :text => "Show".to_s, :count => 2
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "users/new" do
4
+ before(:each) do
5
+ assign(:user, stub_model(User,
6
+ :new => "MyString",
7
+ :index => "MyString",
8
+ :show => "MyString"
9
+ ).as_new_record)
10
+ end
11
+
12
+ it "renders new user form" do
13
+ render
14
+
15
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
16
+ assert_select "form[action=?][method=?]", users_path, "post" do
17
+ assert_select "input#user_new[name=?]", "user[new]"
18
+ assert_select "input#user_index[name=?]", "user[index]"
19
+ assert_select "input#user_show[name=?]", "user[show]"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe "users/show" do
4
+ before(:each) do
5
+ @user = assign(:user, stub_model(User,
6
+ :new => "New",
7
+ :index => "Index",
8
+ :show => "Show"
9
+ ))
10
+ end
11
+
12
+ it "renders attributes in <p>" do
13
+ render
14
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
15
+ rendered.should match(/New/)
16
+ rendered.should match(/Index/)
17
+ rendered.should match(/Show/)
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genderize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bodacious
@@ -61,16 +61,10 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - app/assets/javascripts/genderize/application.js
65
- - app/assets/stylesheets/genderize/application.css
66
- - app/controllers/genderize/application_controller.rb
67
- - app/helpers/genderize/application_helper.rb
68
- - app/views/layouts/genderize/application.html.erb
69
64
  - config/locales/genderize.en.yml
70
65
  - config/routes.rb
71
66
  - lib/genderize/engine.rb
72
67
  - lib/genderize/gender.rb
73
- - lib/genderize/genderize.rb
74
68
  - lib/genderize/version.rb
75
69
  - lib/genderize.rb
76
70
  - lib/generators/genderize/install/install_generator.rb
@@ -79,7 +73,14 @@ files:
79
73
  - MIT-LICENSE
80
74
  - Rakefile
81
75
  - README.md
76
+ - spec/dummy/app/controllers/users_controller.rb
77
+ - spec/dummy/app/helpers/users_helper.rb
82
78
  - spec/dummy/app/models/user.rb
79
+ - spec/dummy/app/views/users/_form.html.erb
80
+ - spec/dummy/app/views/users/edit.html.erb
81
+ - spec/dummy/app/views/users/index.html.erb
82
+ - spec/dummy/app/views/users/new.html.erb
83
+ - spec/dummy/app/views/users/show.html.erb
83
84
  - spec/dummy/config/application.rb
84
85
  - spec/dummy/config/boot.rb
85
86
  - spec/dummy/config/database.yml
@@ -105,7 +106,15 @@ files:
105
106
  - spec/dummy/Rakefile
106
107
  - spec/dummy/README.rdoc
107
108
  - spec/dummy/script/rails
109
+ - spec/dummy/spec/controllers/users_controller_spec.rb
110
+ - spec/dummy/spec/helpers/users_helper_spec.rb
108
111
  - spec/dummy/spec/models/user_spec.rb
112
+ - spec/dummy/spec/requests/users_spec.rb
113
+ - spec/dummy/spec/routing/users_routing_spec.rb
114
+ - spec/dummy/spec/views/users/edit.html.erb_spec.rb
115
+ - spec/dummy/spec/views/users/index.html.erb_spec.rb
116
+ - spec/dummy/spec/views/users/new.html.erb_spec.rb
117
+ - spec/dummy/spec/views/users/show.html.erb_spec.rb
109
118
  - spec/genderize_spec.rb
110
119
  - spec/lib/gender_spec.rb
111
120
  - spec/spec_helper.rb
@@ -135,7 +144,14 @@ signing_key:
135
144
  specification_version: 4
136
145
  summary: A helpful class for gender-specific models in Ruby applications
137
146
  test_files:
147
+ - spec/dummy/app/controllers/users_controller.rb
148
+ - spec/dummy/app/helpers/users_helper.rb
138
149
  - spec/dummy/app/models/user.rb
150
+ - spec/dummy/app/views/users/_form.html.erb
151
+ - spec/dummy/app/views/users/edit.html.erb
152
+ - spec/dummy/app/views/users/index.html.erb
153
+ - spec/dummy/app/views/users/new.html.erb
154
+ - spec/dummy/app/views/users/show.html.erb
139
155
  - spec/dummy/config/application.rb
140
156
  - spec/dummy/config/boot.rb
141
157
  - spec/dummy/config/database.yml
@@ -161,7 +177,15 @@ test_files:
161
177
  - spec/dummy/Rakefile
162
178
  - spec/dummy/README.rdoc
163
179
  - spec/dummy/script/rails
180
+ - spec/dummy/spec/controllers/users_controller_spec.rb
181
+ - spec/dummy/spec/helpers/users_helper_spec.rb
164
182
  - spec/dummy/spec/models/user_spec.rb
183
+ - spec/dummy/spec/requests/users_spec.rb
184
+ - spec/dummy/spec/routing/users_routing_spec.rb
185
+ - spec/dummy/spec/views/users/edit.html.erb_spec.rb
186
+ - spec/dummy/spec/views/users/index.html.erb_spec.rb
187
+ - spec/dummy/spec/views/users/new.html.erb_spec.rb
188
+ - spec/dummy/spec/views/users/show.html.erb_spec.rb
165
189
  - spec/genderize_spec.rb
166
190
  - spec/lib/gender_spec.rb
167
191
  - spec/spec_helper.rb
@@ -1,15 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require jquery
14
- //= require jquery_ujs
15
- //= require_tree .
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
@@ -1,4 +0,0 @@
1
- module Genderize
2
- class ApplicationController < ActionController::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Genderize
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Genderize</title>
5
- <%= stylesheet_link_tag "genderize/application", :media => "all" %>
6
- <%= javascript_include_tag "genderize/application" %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,51 +0,0 @@
1
- module Genderize::Genderize
2
-
3
- def self.included(base)
4
- base.extend(Genderize::Genderize::ClassMethods)
5
- end
6
-
7
- module ClassMethods
8
- require "genderize/gender"
9
-
10
- def genderize(col_name = "gender")
11
- # Reads the DB column value for gender attribute and creates a new Gender
12
- # object with it's value
13
- #
14
- # The object is memoized for future calls.
15
- #
16
- # Returns a Gender
17
- define_method col_name do
18
- if value = instance_variable_get("@#{col_name}")
19
- return value
20
- end
21
- read_value = read_attribute(col_name)
22
- if read_value.blank?
23
- return read_value
24
- else
25
- instance_variable_set("@#{col_name}", Genderize::Gender.new(read_attribute(col_name)))
26
- end
27
- end
28
-
29
- # Writes to the DB column the new value for the gender attribute
30
- # Sets the instance varaible value too
31
- #
32
- # string - A String indicating the gender. Must be either 'm', "M", 'f' or "F".
33
- #
34
- # Raises ArgumentError if gender is not a single alphanumeric character "m" or "f"
35
- define_method "#{col_name}=" do |string|
36
- unless string.blank? or string.to_s =~ /\A(m|f)\Z/i
37
- raise ArgumentError, "Gender must be a single alphanumeric character"
38
- end
39
- write_attribute(col_name, string)
40
-
41
- if string.blank?
42
- instance_variable_set("@#{col_name}", string)
43
- else
44
- instance_variable_set("@#{col_name}", Genderize::Gender.new(read_attribute(col_name)))
45
- end
46
- end
47
-
48
- end
49
-
50
- end
51
- end