has_token_id 0.4.1 → 0.4.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b71462bcbb1b858915c9ad61261c07c7eb1e8cdd
4
- data.tar.gz: 34adb9bb64687b03a4c4a2518ebce32f72fce2b9
3
+ metadata.gz: ee4ece1e713f29cebb06cbf0adcf72442e33b286
4
+ data.tar.gz: 18919caf99be5cbe289e4db5b9b24a0bbe05dbb6
5
5
  SHA512:
6
- metadata.gz: 8bc4ff69f5758624be60644bb01efab78c85146a08100a73d3aa6e3520bb806f8d0312dd827f1355c9dd889d917ed5568bc1f44eda8dc6f5466c1676613dbfef
7
- data.tar.gz: 6137d842644e1442354a02fde9b781ab8986429af5029b6f9d6018bda7ade0b42358053338ae0b7d48ef3646f4b1c49e090c43cd0946bc6c41a333570577a9b7
6
+ metadata.gz: 6d6f647494b39d8defdc179f02339c38dd2f85c5672ac547199b7c2c1354b5d13d3423260767cc8b9b0421647df5a94a5b098bbb036c39ba58a1f2e0acfcf923
7
+ data.tar.gz: 2cdfbe07ee7a237aec3111d115983b3711c7ca05bc95a44d4f7e5bf0c9d40297a72c9b289c57b8c006f5214c35196cccb60fdef45b215f01d1b4ced7b8ba6094
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
+ before_install: "gem update bundler"
1
2
  before_script: "bundle exec dummier"
2
3
 
3
4
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
5
  - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.3
8
+ - 2.2.3
9
+ - 2.3.1
7
10
  - rbx
8
11
  - ree
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # has_token_id [![Build Status](https://secure.travis-ci.org/citrus/has_token_id.png)](http://travis-ci.org/citrus/has_token_id)
1
+ # has_token_id [![Build Status](https://travis-ci.org/citrus/has_token_id.svg?branch=master)](https://travis-ci.org/citrus/has_token_id)
2
2
 
3
3
  Identify your active records with random tokens when you don't want your users to see a sequential ID.
4
4
 
@@ -3,16 +3,19 @@ module HasTokenId
3
3
 
4
4
  # Find by token ensuring case sensitivity
5
5
  def find_by_case_sensitive_token(token)
6
+ return if token.nil?
6
7
  where("#{token_with_table_name} = ?", token).first
7
8
  end
8
9
 
9
10
  # Find by token regardless of case
10
11
  def find_by_case_insensitive_token(token)
12
+ return if token.nil?
11
13
  where("lower(#{token_with_table_name}) = ?", token.downcase).first
12
14
  end
13
15
 
14
16
  # Find by token
15
17
  def find_by_token(token)
18
+ return if token.nil?
16
19
  send(has_token_id_options[:case_sensitive] ? :find_by_case_sensitive_token : :find_by_case_insensitive_token, token)
17
20
  end
18
21
 
@@ -1,3 +1,3 @@
1
1
  module HasTokenId
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -70,88 +70,6 @@ class ConcernTest < MiniTest::Should::TestCase
70
70
  assert_equal 24, @item.short_token.length
71
71
  end
72
72
 
73
- should "find by token" do
74
- assert_equal @item, Item.find(@item.token)
75
- end
76
-
77
- should "work with token finder method" do
78
- assert Item.find_by_token(@item.token)
79
- end
80
-
81
- should "work with !bang token finder method" do
82
- assert Item.find_by_token!(@item.token)
83
- end
84
-
85
- should "return nil from token finder method when record is not found" do
86
- assert_equal nil, Item.find_by_token("invalid")
87
- end
88
-
89
- should "raise activerecord not found from !bang token finder method when record is not found" do
90
- assert_raises ActiveRecord::RecordNotFound do
91
- Item.find_by_token!("invalid")
92
- end
93
- end
94
-
95
- context "when case sensitivity is disabled" do
96
-
97
- setup do
98
- Item.has_token_id_options[:case_sensitive] = false
99
- end
100
-
101
- should "find by token" do
102
- assert_equal @item, Item.find(@item.token)
103
- assert_equal @item, Item.find_by_token(@item.token)
104
- assert_equal @item, Item.find_by_token!(@item.token)
105
- end
106
-
107
- should "find by token even if it's all uppercase" do
108
- assert_equal @item, Item.find(@item.token.upcase)
109
- assert_equal @item, Item.find_by_token(@item.token.upcase)
110
- assert_equal @item, Item.find_by_token!(@item.token.upcase)
111
- end
112
-
113
- should "find by token even if it's all lowercase" do
114
- assert_equal @item, Item.find(@item.token.downcase)
115
- assert_equal @item, Item.find_by_token(@item.token.downcase)
116
- assert_equal @item, Item.find_by_token!(@item.token.downcase)
117
- end
118
-
119
- end
120
-
121
- context "when case sensitivity is enabled" do
122
-
123
- setup do
124
- Item.has_token_id_options[:case_sensitive] = true
125
- end
126
-
127
- should "find by token" do
128
- assert_equal @item, Item.find(@item.token)
129
- assert_equal @item, Item.find_by_token(@item.token)
130
- assert_equal @item, Item.find_by_token!(@item.token)
131
- end
132
-
133
- should "not find by token if it's all uppercase" do
134
- assert_raises ActiveRecord::RecordNotFound do
135
- Item.find(@item.token.upcase)
136
- end
137
- assert_equal nil, Item.find_by_token(@item.token.upcase)
138
- assert_raises ActiveRecord::RecordNotFound do
139
- Item.find_by_token!(@item.token.upcase)
140
- end
141
- end
142
-
143
- should "not find by token if it's all lowercase" do
144
- assert_raises ActiveRecord::RecordNotFound do
145
- Item.find(@item.token.downcase)
146
- end
147
- assert_equal nil, Item.find_by_token(@item.token.downcase)
148
- assert_raises ActiveRecord::RecordNotFound do
149
- assert Item.find_by_token!(@item.token.downcase)
150
- end
151
- end
152
-
153
- end
154
-
155
73
  end
156
74
 
157
75
  context "with a long token" do
@@ -0,0 +1,100 @@
1
+ require "test_helper"
2
+
3
+ # We'll test the test/dummy/app/item.rb model
4
+
5
+ class FinderMethodsTest < MiniTest::Should::TestCase
6
+
7
+ setup do
8
+ # remove all items
9
+ Item.destroy_all
10
+ # reset to defaults
11
+ Item.has_token_id_options.merge!(Item.default_token_options)
12
+ @item = Item.create(:name => "Blue Cheese Burger")
13
+ end
14
+
15
+ should "find by using default find method" do
16
+ assert_equal @item, Item.find(@item.token)
17
+ end
18
+
19
+ should "work with token finder method" do
20
+ assert Item.find_by_token(@item.token)
21
+ end
22
+
23
+ should "return nil when token is nil" do
24
+ assert_nil Item.find_by_token(nil)
25
+ end
26
+
27
+ should "work with !bang token finder method" do
28
+ assert Item.find_by_token!(@item.token)
29
+ end
30
+
31
+ should "return nil from token finder method when record is not found" do
32
+ assert_equal nil, Item.find_by_token("invalid")
33
+ end
34
+
35
+ should "raise activerecord not found from !bang token finder method when record is not found" do
36
+ assert_raises ActiveRecord::RecordNotFound do
37
+ Item.find_by_token!("invalid")
38
+ end
39
+ end
40
+
41
+ context "when case sensitivity is disabled" do
42
+
43
+ setup do
44
+ Item.has_token_id_options[:case_sensitive] = false
45
+ end
46
+
47
+ should "find by token" do
48
+ assert_equal @item, Item.find(@item.token)
49
+ assert_equal @item, Item.find_by_token(@item.token)
50
+ assert_equal @item, Item.find_by_token!(@item.token)
51
+ end
52
+
53
+ should "find by token even if it's all uppercase" do
54
+ assert_equal @item, Item.find(@item.token.upcase)
55
+ assert_equal @item, Item.find_by_token(@item.token.upcase)
56
+ assert_equal @item, Item.find_by_token!(@item.token.upcase)
57
+ end
58
+
59
+ should "find by token even if it's all lowercase" do
60
+ assert_equal @item, Item.find(@item.token.downcase)
61
+ assert_equal @item, Item.find_by_token(@item.token.downcase)
62
+ assert_equal @item, Item.find_by_token!(@item.token.downcase)
63
+ end
64
+
65
+ end
66
+
67
+ context "when case sensitivity is enabled" do
68
+
69
+ setup do
70
+ Item.has_token_id_options[:case_sensitive] = true
71
+ end
72
+
73
+ should "find by token" do
74
+ assert_equal @item, Item.find(@item.token)
75
+ assert_equal @item, Item.find_by_token(@item.token)
76
+ assert_equal @item, Item.find_by_token!(@item.token)
77
+ end
78
+
79
+ should "not find by token if it's all uppercase" do
80
+ assert_raises ActiveRecord::RecordNotFound do
81
+ Item.find(@item.token.upcase)
82
+ end
83
+ assert_equal nil, Item.find_by_token(@item.token.upcase)
84
+ assert_raises ActiveRecord::RecordNotFound do
85
+ Item.find_by_token!(@item.token.upcase)
86
+ end
87
+ end
88
+
89
+ should "not find by token if it's all lowercase" do
90
+ assert_raises ActiveRecord::RecordNotFound do
91
+ Item.find(@item.token.downcase)
92
+ end
93
+ assert_equal nil, Item.find_by_token(@item.token.downcase)
94
+ assert_raises ActiveRecord::RecordNotFound do
95
+ assert Item.find_by_token!(@item.token.downcase)
96
+ end
97
+ end
98
+
99
+ end
100
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_token_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Steffen
@@ -133,6 +133,7 @@ files:
133
133
  - test/support/test_case.rb
134
134
  - test/test_helper.rb
135
135
  - test/unit/concern_test.rb
136
+ - test/unit/finder_methods_test.rb
136
137
  - test/unit/has_token_id_test.rb
137
138
  - test/unit/table_definition_test.rb
138
139
  homepage: https://github.com/citrus/has_token_id
@@ -165,5 +166,6 @@ test_files:
165
166
  - test/support/test_case.rb
166
167
  - test/test_helper.rb
167
168
  - test/unit/concern_test.rb
169
+ - test/unit/finder_methods_test.rb
168
170
  - test/unit/has_token_id_test.rb
169
171
  - test/unit/table_definition_test.rb