genderize 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/genderize.rb +14 -20
- data/lib/genderize/version.rb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/environments/production.rb +6 -2
- data/spec/dummy/config/environments/test.rb +9 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +21 -8
- data/spec/dummy/log/test.log +52 -39
- data/spec/dummy/spec/models/user_spec.rb +32 -26
- data/spec/lib/gender_spec.rb +114 -114
- data/spec/spec_helper.rb +3 -2
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f900977dce6ce532aaaaeb0eac75f034ef6f9a6f
|
4
|
+
data.tar.gz: 4a9dfe4d19dd6a31893c72d49d3f692eaea1b5aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ad68c57f62525bfc471f944f8242692debe6473a82bfb15c2379cc02d9f9704d7206e126682d4c59d3c2e07fdd3da13474789f779baa76980c02455d82131f7
|
7
|
+
data.tar.gz: 7d9c2260901360ef81bd9282d0373a1bea5df76a721e1973d79216f83276fda5fb9e0a9a74202d48277479d3ab328670a3d4380e7874ba9fddb4b327893b022b
|
data/lib/genderize.rb
CHANGED
@@ -6,33 +6,27 @@ unless Rails
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Genderize
|
9
|
-
|
9
|
+
|
10
10
|
def self.included(base)
|
11
11
|
base.extend(ClassMethods)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
module ClassMethods
|
15
15
|
|
16
|
-
|
16
|
+
|
17
17
|
def genderize(col_name = "gender")
|
18
|
-
# Reads the DB column value for gender attribute and creates a new Gender
|
18
|
+
# Reads the DB column value for gender attribute and creates a new Gender
|
19
19
|
# object with it's value
|
20
20
|
#
|
21
21
|
# The object is memoized for future calls.
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# Returns a Gender
|
24
24
|
define_method col_name do
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
25
|
+
current_value = instance_variable_get("@#{col_name}")
|
26
|
+
persist_value = Genderize::Gender.new(read_attribute(col_name))
|
27
|
+
return current_value || instance_variable_set("@#{col_name}", persist_value)
|
34
28
|
end
|
35
|
-
|
29
|
+
|
36
30
|
# Writes to the DB column the new value for the gender attribute
|
37
31
|
# Sets the instance varaible value too
|
38
32
|
#
|
@@ -41,19 +35,19 @@ module Genderize
|
|
41
35
|
# Raises ArgumentError if gender is not a single alphanumeric character "m" or "f"
|
42
36
|
define_method "#{col_name}=" do |string|
|
43
37
|
string = string.to_s.first
|
44
|
-
unless string.to_s =~ /\A(m|f)\Z/i
|
45
|
-
raise ArgumentError, "Gender must be
|
38
|
+
unless string.to_s =~ /\A(m|f|)\Z/i
|
39
|
+
raise ArgumentError, "Gender must be one of '', 'm', or 'f'"
|
46
40
|
end
|
47
41
|
write_attribute(col_name, string)
|
48
|
-
|
42
|
+
|
49
43
|
if string.blank?
|
50
44
|
instance_variable_set("@#{col_name}", string)
|
51
45
|
else
|
52
46
|
instance_variable_set("@#{col_name}", Genderize::Gender.new(read_attribute(col_name)))
|
53
47
|
end
|
54
48
|
end
|
55
|
-
|
49
|
+
|
56
50
|
end
|
57
|
-
|
51
|
+
|
58
52
|
end
|
59
53
|
end
|
data/lib/genderize/version.rb
CHANGED
@@ -47,7 +47,7 @@ module Dummy
|
|
47
47
|
# This will create an empty whitelist of attributes available for mass-assignment for all models
|
48
48
|
# in your app. As such, your models will need to explicitly whitelist or blacklist accessible
|
49
49
|
# parameters by using an attr_accessible or attr_protected declaration.
|
50
|
-
config.active_record.whitelist_attributes = true
|
50
|
+
config.active_record.whitelist_attributes = true if Rails.version < "4.0.0"
|
51
51
|
|
52
52
|
# Enable the asset pipeline
|
53
53
|
config.assets.enabled = true
|
@@ -19,8 +19,12 @@ Dummy::Application.configure do
|
|
19
19
|
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
|
20
20
|
# config.action_dispatch.rack_cache = true
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
if Rails.version >= "4.2.0"
|
23
|
+
config.serve_static_files = false
|
24
|
+
else
|
25
|
+
# Disable Rails's static asset server (Apache or nginx will already do this).
|
26
|
+
config.serve_static_assets = false
|
27
|
+
end
|
24
28
|
|
25
29
|
# Compress JavaScripts and CSS.
|
26
30
|
config.assets.js_compressor = :uglifier
|
@@ -8,9 +8,8 @@ Dummy::Application.configure do
|
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
10
|
# Configure static asset server for tests with Cache-Control for performance
|
11
|
-
config.serve_static_assets = true
|
12
11
|
config.static_cache_control = "public, max-age=3600"
|
13
|
-
|
12
|
+
|
14
13
|
if Rails.version =~ /\A3/
|
15
14
|
# Log error messages when you accidentally call methods on nil
|
16
15
|
config.whiny_nils = true
|
@@ -20,6 +19,14 @@ Dummy::Application.configure do
|
|
20
19
|
config.eager_load = false
|
21
20
|
end
|
22
21
|
|
22
|
+
if Rails.version >= "4.2.0"
|
23
|
+
config.serve_static_files = false
|
24
|
+
else
|
25
|
+
# Disable Rails's static asset server (Apache or nginx will already do this).
|
26
|
+
config.serve_static_assets = false
|
27
|
+
end
|
28
|
+
|
29
|
+
|
23
30
|
# Show full error reports and disable caching.
|
24
31
|
config.consider_all_requests_local = true
|
25
32
|
config.action_controller.perform_caching = false
|
Binary file
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
ActiveRecord::Schema.define(version: 20130506080641) do
|
15
15
|
|
16
|
-
create_table "users", force:
|
16
|
+
create_table "users", force: :cascade do |t|
|
17
17
|
t.string "name", limit: 20, null: false
|
18
18
|
t.string "gender", limit: 1, null: false
|
19
19
|
t.datetime "created_at"
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -1,11 +1,24 @@
|
|
1
|
-
|
2
|
-
[1m[
|
3
|
-
[1m[
|
4
|
-
|
5
|
-
[1m[35m (0.1ms)[0m begin transaction
|
6
|
-
[1m[36m (0.4ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(20) NOT NULL, "gender" varchar(1) NOT NULL, "created_at" datetime, "updated_at" datetime) [0m
|
7
|
-
[1m[35mSQL (0.2ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130506080641"]]
|
8
|
-
[1m[36m (3.5ms)[0m [1mcommit transaction[0m
|
1
|
+
DEPRECATION WARNING: config.active_record.whitelist_attributes is deprecated and have no effect. Remove its call from the configuration. (called from block in tsort_each at /Users/Gavin/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228)
|
2
|
+
[1m[36m (2.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
3
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
4
|
+
[1m[36m (0.6ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
9
5
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
6
|
+
Migrating to CreateUsers (20130506080641)
|
7
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
8
|
+
DEPRECATION WARNING: `#timestamps` was called without specifying an option for `null`. In Rails 5, this behavior will change to `null: false`. You should manually specify `null: true` to prevent the behavior of your existing migrations from changing. (called from block in change at /Users/Gavin/Clients/KatanaCode/genderize/spec/dummy/db/migrate/20130506080641_create_users.rb:8)
|
9
|
+
[1m[35m (0.5ms)[0m CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(20) NOT NULL, "gender" varchar(1) NOT NULL, "created_at" datetime, "updated_at" datetime)
|
10
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20130506080641"]]
|
11
|
+
[1m[35m (0.7ms)[0m commit transaction
|
10
12
|
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
13
|
+
DEPRECATION WARNING: config.active_record.whitelist_attributes is deprecated and have no effect. Remove its call from the configuration. (called from block in tsort_each at /Users/Gavin/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228)
|
14
|
+
[1m[36m (2.9ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
15
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
16
|
+
[1m[36m (0.8ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
11
17
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
18
|
+
Migrating to CreateUsers (20130506080641)
|
19
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
20
|
+
DEPRECATION WARNING: `#timestamps` was called without specifying an option for `null`. In Rails 5, this behavior will change to `null: false`. You should manually specify `null: true` to prevent the behavior of your existing migrations from changing. (called from block in change at /Users/Gavin/Clients/KatanaCode/genderize/spec/dummy/db/migrate/20130506080641_create_users.rb:8)
|
21
|
+
[1m[35m (0.3ms)[0m CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(20) NOT NULL, "gender" varchar(1) NOT NULL, "created_at" datetime, "updated_at" datetime)
|
22
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20130506080641"]]
|
23
|
+
[1m[35m (0.7ms)[0m commit transaction
|
24
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.0ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
data/spec/dummy/log/test.log
CHANGED
@@ -1,45 +1,58 @@
|
|
1
|
-
[1m[36m (
|
2
|
-
[1m[35m (
|
3
|
-
[1m[
|
4
|
-
Migrating to CreateUsers (20130506080641)
|
5
|
-
[1m[35m (0.1ms)[0m begin transaction
|
6
|
-
[1m[36m (0.5ms)[0m [1mCREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(20) NOT NULL, "gender" varchar(1) NOT NULL, "created_at" datetime, "updated_at" datetime) [0m
|
7
|
-
[1m[35mSQL (0.3ms)[0m INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20130506080641"]]
|
8
|
-
[1m[36m (3.0ms)[0m [1mcommit transaction[0m
|
1
|
+
[1m[36m (2.6ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
2
|
+
[1m[35m (0.0ms)[0m select sqlite_version(*)
|
3
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
9
4
|
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
10
|
-
|
11
|
-
[1m[
|
5
|
+
Migrating to CreateUsers (20130506080641)
|
6
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
7
|
+
[1m[35m (0.3ms)[0m CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(20) NOT NULL, "gender" varchar(1) NOT NULL, "created_at" datetime, "updated_at" datetime)
|
8
|
+
[1m[36mSQL (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES (?)[0m [["version", "20130506080641"]]
|
9
|
+
[1m[35m (0.5ms)[0m commit transaction
|
10
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
11
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
12
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:22:21.503307"], ["updated_at", "2016-05-27 13:22:21.503307"]]
|
13
|
+
[1m[36m (2.7ms)[0m [1mcommit transaction[0m
|
14
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
15
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
16
|
+
[1m[35mSQL (0.4ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:22:53.702225"], ["updated_at", "2016-05-27 13:22:53.702225"]]
|
12
17
|
[1m[36m (2.5ms)[0m [1mcommit transaction[0m
|
13
|
-
[1m[35mUser Load (0.
|
14
|
-
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
15
|
-
[1m[35mSQL (3.3ms)[0m INSERT INTO "users" ("created_at", "gender", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Mon, 30 Jun 2014 22:08:19 UTC +00:00], ["gender", "f"], ["name", "f"], ["updated_at", Mon, 30 Jun 2014 22:08:19 UTC +00:00]]
|
16
|
-
[1m[36m (53.4ms)[0m [1mcommit transaction[0m
|
17
|
-
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
18
|
-
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
19
|
-
[1m[35mSQL (2.3ms)[0m INSERT INTO "users" ("created_at", "gender", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Mon, 30 Jun 2014 22:08:51 UTC +00:00], ["gender", "f"], ["name", "f"], ["updated_at", Mon, 30 Jun 2014 22:08:51 UTC +00:00]]
|
20
|
-
[1m[36m (51.2ms)[0m [1mcommit transaction[0m
|
21
|
-
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
18
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
22
19
|
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
23
|
-
[1m[35mSQL (
|
20
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:28:16.419497"], ["updated_at", "2016-05-27 13:28:16.419497"]]
|
21
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
22
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
23
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
24
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:29:04.891644"], ["updated_at", "2016-05-27 13:29:04.891644"]]
|
25
|
+
[1m[36m (2.5ms)[0m [1mcommit transaction[0m
|
26
|
+
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
27
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
28
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:29:41.054526"], ["updated_at", "2016-05-27 13:29:41.054526"]]
|
24
29
|
[1m[36m (2.7ms)[0m [1mcommit transaction[0m
|
25
|
-
[1m[35mUser Load (0.
|
26
|
-
[1m[36m (0.
|
27
|
-
[1m[35mSQL (
|
28
|
-
[1m[36m (
|
29
|
-
[1m[35mUser Load (0.2ms)[0m SELECT
|
30
|
-
[1m[36m (0.
|
31
|
-
[1m[35mSQL (
|
30
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
31
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
32
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:30:10.725246"], ["updated_at", "2016-05-27 13:30:10.725246"]]
|
33
|
+
[1m[36m (2.6ms)[0m [1mcommit transaction[0m
|
34
|
+
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
35
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
36
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:31:19.111752"], ["updated_at", "2016-05-27 13:31:19.111752"]]
|
32
37
|
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
33
|
-
[1m[35mUser Load (0.
|
34
|
-
[1m[36m (0.
|
35
|
-
[1m[35mSQL (
|
36
|
-
[1m[36m (
|
37
|
-
[1m[35mUser Load (0.
|
38
|
-
[1m[36m (0.
|
39
|
-
[1m[35mSQL (
|
38
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
39
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
40
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:31:42.590594"], ["updated_at", "2016-05-27 13:31:42.590594"]]
|
41
|
+
[1m[36m (2.6ms)[0m [1mcommit transaction[0m
|
42
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
43
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
44
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:31:58.855684"], ["updated_at", "2016-05-27 13:31:58.855684"]]
|
45
|
+
[1m[36m (2.2ms)[0m [1mcommit transaction[0m
|
46
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
47
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
48
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:32:11.842003"], ["updated_at", "2016-05-27 13:32:11.842003"]]
|
49
|
+
[1m[36m (2.4ms)[0m [1mcommit transaction[0m
|
50
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
51
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
52
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:32:49.476375"], ["updated_at", "2016-05-27 13:32:49.476375"]]
|
53
|
+
[1m[36m (2.6ms)[0m [1mcommit transaction[0m
|
54
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
55
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
56
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "users" ("name", "gender", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["name", "f"], ["gender", "f"], ["created_at", "2016-05-27 13:33:00.356946"], ["updated_at", "2016-05-27 13:33:00.356946"]]
|
40
57
|
[1m[36m (2.5ms)[0m [1mcommit transaction[0m
|
41
|
-
[1m[35mUser Load (0.
|
42
|
-
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
43
|
-
[1m[35mSQL (2.3ms)[0m INSERT INTO "users" ("created_at", "gender", "name", "updated_at") VALUES (?, ?, ?, ?) [["created_at", Mon, 30 Jun 2014 22:13:48 UTC +00:00], ["gender", "f"], ["name", "f"], ["updated_at", Mon, 30 Jun 2014 22:13:48 UTC +00:00]]
|
44
|
-
[1m[36m (54.8ms)[0m [1mcommit transaction[0m
|
45
|
-
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
58
|
+
[1m[35mUser Load (0.1ms)[0m SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT 1
|
@@ -1,57 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe User do
|
4
|
-
|
3
|
+
describe User, type: :model do
|
4
|
+
|
5
5
|
describe "gender" do
|
6
|
-
|
6
|
+
|
7
7
|
let(:user) { User.new(gender: "f") }
|
8
|
-
|
8
|
+
|
9
9
|
it "should return a Gender object" do
|
10
|
-
user.gender.
|
10
|
+
expect(user.gender).to be_an_instance_of(Genderize::Gender)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should be female?" do
|
14
|
-
user.gender.
|
14
|
+
expect(user.gender).to be_female
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
it "should be male when changed" do
|
18
18
|
user.gender = "m"
|
19
|
-
user.gender.
|
19
|
+
expect(user.gender).to be_male
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
it "should be blank when changed" do
|
23
|
+
user.gender = ""
|
24
|
+
expect(user.gender).to be_empty
|
25
|
+
end
|
26
|
+
|
22
27
|
end
|
23
|
-
|
28
|
+
|
24
29
|
describe "full gender names" do
|
25
|
-
|
30
|
+
|
26
31
|
it 'should set the gender as the abbreviation' do
|
27
|
-
User.new(gender: "female").gender.
|
28
|
-
User.new(gender: "male").gender.
|
32
|
+
expect(User.new(gender: "female").gender).to be_female
|
33
|
+
expect(User.new(gender: "male").gender).to be_male
|
34
|
+
expect(User.new(gender: "").gender).to be_blank
|
29
35
|
end
|
30
|
-
|
36
|
+
|
31
37
|
end
|
32
38
|
# Since the db column name can be changed, we're using the "name" column to
|
33
39
|
# test this behaviour
|
34
40
|
describe "name" do
|
35
|
-
|
41
|
+
|
36
42
|
let(:user) { User.new(name: "f", gender: "f") }
|
37
|
-
|
43
|
+
|
38
44
|
it "should return a Gender object" do
|
39
|
-
user.name.
|
45
|
+
expect(user.name).to be_an_instance_of Genderize::Gender
|
40
46
|
end
|
41
|
-
|
47
|
+
|
42
48
|
it "should change the name column" do
|
43
49
|
user.save!
|
44
50
|
user = User.last
|
45
|
-
user.name.
|
46
|
-
user.name.
|
51
|
+
expect(user.name).to eq("f")
|
52
|
+
expect(user.name).to be_female
|
47
53
|
end
|
48
|
-
|
54
|
+
|
49
55
|
it "should not change the gender column" do
|
50
56
|
user.name = "m"
|
51
|
-
user.name.
|
52
|
-
user.gender.
|
57
|
+
expect(user.name).to be_male
|
58
|
+
expect(user.gender).not_to be_male
|
53
59
|
end
|
54
|
-
|
60
|
+
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
end
|
data/spec/lib/gender_spec.rb
CHANGED
@@ -1,232 +1,232 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Genderize::Gender do
|
4
|
-
|
4
|
+
|
5
5
|
let(:female) { Gender.new("f") }
|
6
|
-
let(:male)
|
7
|
-
let(:blank)
|
8
|
-
|
6
|
+
let(:male) { Gender.new("M") }
|
7
|
+
let(:blank) { Gender.new('') }
|
8
|
+
|
9
9
|
context "when full gender name is used" do
|
10
|
-
|
10
|
+
|
11
11
|
it "should find the correct abbreviation" do
|
12
|
-
Gender.new("female").abbr.
|
13
|
-
Gender.new("male").abbr.
|
12
|
+
expect(Gender.new("female").abbr).to eql('f')
|
13
|
+
expect(Gender.new("male").abbr).to eql('m')
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
19
|
describe :name do
|
20
|
-
|
20
|
+
|
21
21
|
context "when male" do
|
22
|
-
|
22
|
+
|
23
23
|
it "should be 'male'" do
|
24
|
-
male.name.
|
24
|
+
expect(male.name).to eql("male")
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
end
|
28
28
|
|
29
29
|
context "when female" do
|
30
|
-
|
30
|
+
|
31
31
|
it "should be 'female'" do
|
32
|
-
female.name.
|
32
|
+
expect(female.name).to eql("female")
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
context "when blank" do
|
38
|
-
|
38
|
+
|
39
39
|
it "should be nil" do
|
40
|
-
blank.name.
|
40
|
+
expect(blank.name).to be_nil
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
|
46
46
|
end
|
47
|
-
|
48
|
-
describe :abbr do
|
49
|
-
|
47
|
+
|
48
|
+
describe :abbr do
|
49
|
+
|
50
50
|
context "when male" do
|
51
|
-
|
51
|
+
|
52
52
|
it "should be 'm'" do
|
53
|
-
male.abbr.
|
53
|
+
expect(male.abbr).to eql("m")
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
end
|
57
57
|
|
58
58
|
context "when female" do
|
59
|
-
|
59
|
+
|
60
60
|
it "should be 'f'" do
|
61
|
-
female.abbr.
|
61
|
+
expect(female.abbr).to eql("f")
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
context "when blank" do
|
67
|
-
|
67
|
+
|
68
68
|
it "should be nil" do
|
69
|
-
blank.abbr.
|
69
|
+
expect(blank.abbr).to be_nil
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
end
|
73
|
-
|
74
|
-
|
73
|
+
|
74
|
+
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
describe :subject do
|
78
|
-
|
78
|
+
|
79
79
|
context "when male" do
|
80
|
-
|
80
|
+
|
81
81
|
it "should be 'he'" do
|
82
|
-
male.subject.
|
82
|
+
expect(male.subject).to eql("he")
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
end
|
86
86
|
|
87
87
|
context "when female" do
|
88
|
-
|
88
|
+
|
89
89
|
it "should be 'she'" do
|
90
|
-
female.subject.
|
90
|
+
expect(female.subject).to eql("she")
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
context "when blank" do
|
96
|
-
|
96
|
+
|
97
97
|
it "should be nil" do
|
98
|
-
blank.subject.
|
98
|
+
expect(blank.subject).to be_nil
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
describe :object do
|
106
106
|
|
107
107
|
context "when male" do
|
108
|
-
|
108
|
+
|
109
109
|
it "should be 'him'" do
|
110
|
-
male.object.
|
110
|
+
expect(male.object).to eql("him")
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
end
|
114
114
|
|
115
115
|
context "when female" do
|
116
|
-
|
116
|
+
|
117
117
|
it "should be 'her'" do
|
118
|
-
female.object.
|
118
|
+
expect(female.object).to eql("her")
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
end
|
122
122
|
|
123
123
|
context "when blank" do
|
124
|
-
|
124
|
+
|
125
125
|
it "should be nil" do
|
126
|
-
blank.object.
|
126
|
+
expect(blank.object).to be_nil
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
describe :possessive do
|
135
|
-
|
135
|
+
|
136
136
|
context "when male" do
|
137
|
-
|
137
|
+
|
138
138
|
it "should be 'his'" do
|
139
|
-
male.possessive.
|
139
|
+
expect(male.possessive).to eql("his")
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
end
|
143
143
|
|
144
144
|
context "when female" do
|
145
|
-
|
145
|
+
|
146
146
|
it "should be 'her'" do
|
147
|
-
female.possessive.
|
147
|
+
expect(female.possessive).to eql("her")
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
context "when blank" do
|
153
|
-
|
153
|
+
|
154
154
|
it "should be nil" do
|
155
|
-
blank.possessive.
|
155
|
+
expect(blank.possessive).to be_nil
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
end
|
159
|
-
|
160
|
-
|
161
|
-
|
159
|
+
|
160
|
+
|
161
|
+
|
162
162
|
end
|
163
|
-
|
163
|
+
|
164
164
|
describe :casual do
|
165
|
-
|
165
|
+
|
166
166
|
context "when male" do
|
167
|
-
|
167
|
+
|
168
168
|
it "should be 'guy'" do
|
169
|
-
male.casual.
|
169
|
+
expect(male.casual).to eql("guy")
|
170
170
|
end
|
171
|
-
|
171
|
+
|
172
172
|
end
|
173
173
|
|
174
174
|
context "when female" do
|
175
|
-
|
175
|
+
|
176
176
|
it "should be 'girl'" do
|
177
|
-
female.casual.
|
177
|
+
expect(female.casual).to eql("girl")
|
178
178
|
end
|
179
|
-
|
179
|
+
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
context "when blank" do
|
183
|
-
|
183
|
+
|
184
184
|
it "should be nil" do
|
185
|
-
blank.casual.
|
185
|
+
expect(blank.casual).to be_nil
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
end
|
189
|
-
|
190
|
-
|
189
|
+
|
190
|
+
|
191
191
|
end
|
192
|
-
|
192
|
+
|
193
193
|
describe :to_s do
|
194
|
-
|
194
|
+
|
195
195
|
it "should equal the abbr value" do
|
196
|
-
male.to_s.
|
197
|
-
female.to_s.
|
196
|
+
expect(male.to_s).to eql(male.abbr)
|
197
|
+
expect(female.to_s).to eql(female.abbr)
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
it "returns a string" do
|
201
|
-
male.to_s.
|
202
|
-
female.to_s.
|
201
|
+
expect(male.to_s).to be_an_instance_of(String)
|
202
|
+
expect(female.to_s).to be_an_instance_of(String)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
end
|
206
|
-
|
206
|
+
|
207
207
|
describe :capital_abbr do
|
208
|
-
|
208
|
+
|
209
209
|
it "should equal the abbr value capitalized" do
|
210
|
-
male.capital_abbr.
|
211
|
-
female.capital_abbr.
|
210
|
+
expect(male.capital_abbr).to eql(male.abbr.capitalize)
|
211
|
+
expect(female.capital_abbr).to eql(female.abbr.capitalize)
|
212
212
|
end
|
213
|
-
|
213
|
+
|
214
214
|
end
|
215
|
-
|
215
|
+
|
216
216
|
describe :== do
|
217
|
-
|
217
|
+
|
218
218
|
it "should return true if passed abbr value" do
|
219
|
-
(male == "m").
|
220
|
-
(female == "f").
|
221
|
-
(blank == nil).
|
219
|
+
expect(male == "m").to be_truthy
|
220
|
+
expect(female == "f").to be_truthy
|
221
|
+
expect(blank == nil).to be_truthy
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should return false if not passed abbr value" do
|
225
|
-
(male == "f").
|
226
|
-
(female == 1).
|
227
|
-
(blank == "$").
|
225
|
+
expect(male == "f").to be_falsey
|
226
|
+
expect(female == 1).to be_falsey
|
227
|
+
expect(blank == "$").to be_falsey
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,10 @@ require File.expand_path("../dummy/config/environment", __FILE__)
|
|
5
5
|
require 'rspec/rails'
|
6
6
|
require "support/deferred_garbage_collection"
|
7
7
|
|
8
|
-
|
8
|
+
require "genderize"
|
9
|
+
include Genderize # make the Gender class available in specs
|
9
10
|
|
10
11
|
RSpec.configure do |config|
|
11
12
|
config.before(:all) { DeferredGarbageCollection.start }
|
12
|
-
config.after(:all)
|
13
|
+
config.after(:all) { DeferredGarbageCollection.reconsider }
|
13
14
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: genderize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bodacious
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sqlite3
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: A helpful class for gender-specific models in Ruby applications. Genderize
|
@@ -61,19 +61,21 @@ executables: []
|
|
61
61
|
extensions: []
|
62
62
|
extra_rdoc_files: []
|
63
63
|
files:
|
64
|
+
- MIT-LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
64
67
|
- config/locales/genderize.en.yml
|
65
68
|
- config/locales/genderize.es.yml
|
66
69
|
- config/routes.rb
|
70
|
+
- lib/genderize.rb
|
67
71
|
- lib/genderize/engine.rb
|
68
72
|
- lib/genderize/gender.rb
|
69
73
|
- lib/genderize/version.rb
|
70
|
-
- lib/genderize.rb
|
71
|
-
- lib/generators/genderize/install/install_generator.rb
|
72
74
|
- lib/generators/genderize/install/USAGE
|
75
|
+
- lib/generators/genderize/install/install_generator.rb
|
73
76
|
- lib/tasks/genderize_tasks.rake
|
74
|
-
-
|
75
|
-
- Rakefile
|
76
|
-
- README.md
|
77
|
+
- spec/dummy/README.rdoc
|
78
|
+
- spec/dummy/Rakefile
|
77
79
|
- spec/dummy/app/helpers/users_helper.rb
|
78
80
|
- spec/dummy/app/models/user.rb
|
79
81
|
- spec/dummy/app/views/users/_form.html.erb
|
@@ -81,6 +83,7 @@ files:
|
|
81
83
|
- spec/dummy/app/views/users/index.html.erb
|
82
84
|
- spec/dummy/app/views/users/new.html.erb
|
83
85
|
- spec/dummy/app/views/users/show.html.erb
|
86
|
+
- spec/dummy/config.ru
|
84
87
|
- spec/dummy/config/application.rb
|
85
88
|
- spec/dummy/config/boot.rb
|
86
89
|
- spec/dummy/config/database.yml
|
@@ -96,15 +99,12 @@ files:
|
|
96
99
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
97
100
|
- spec/dummy/config/locales/en.yml
|
98
101
|
- spec/dummy/config/routes.rb
|
99
|
-
- spec/dummy/config.ru
|
100
102
|
- spec/dummy/db/development.sqlite3
|
101
103
|
- spec/dummy/db/migrate/20130506080641_create_users.rb
|
102
104
|
- spec/dummy/db/schema.rb
|
103
105
|
- spec/dummy/db/test.sqlite3
|
104
106
|
- spec/dummy/log/development.log
|
105
107
|
- spec/dummy/log/test.log
|
106
|
-
- spec/dummy/Rakefile
|
107
|
-
- spec/dummy/README.rdoc
|
108
108
|
- spec/dummy/script/rails
|
109
109
|
- spec/dummy/spec/models/user_spec.rb
|
110
110
|
- spec/genderize_spec.rb
|
@@ -121,17 +121,17 @@ require_paths:
|
|
121
121
|
- lib
|
122
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.6.3
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A helpful class for gender-specific models in Ruby applications
|