acts_as_hashids 0.1.5 → 0.1.6

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
- SHA1:
3
- metadata.gz: 566fc3dc46c7d62d6b380440acc8f5b58a168be0
4
- data.tar.gz: bd082d7e564dad63be19230dd89c5662b111d1b1
2
+ SHA256:
3
+ metadata.gz: c5b2d3eb197bd3107dd4ddfea07983d1d630caa4ee38826d26d2fef4f304b072
4
+ data.tar.gz: f25d68793d382f453f28ffe86cc56382719b93de6062fcbd924d0c8ef1402d33
5
5
  SHA512:
6
- metadata.gz: 359269409ec054b38093f527a6b57b2b0ee6bae5103828e40d14504a897901e4eb72f42b2e486350ebd352500c79f83603bc611ec2fa41155c30b341bcc5880c
7
- data.tar.gz: 89b03a0959d3bd501b047d1d42cd0110d3419420116936fe31a58f5023d7be6f2341e93fa32341adcbf3b658fc77ad4399977ae1c384d5fed7e9cbaa772e54c9
6
+ metadata.gz: 435ab3722ecb4a43578463c93296c7bd9759f416ef85df10cfb11558f8e49be3759f8e2a825e388776af773f0d4d908606653a53eea3414fac9a32e86d445a11
7
+ data.tar.gz: a9251eee6f872cf9a99529049d74fec714f7473afb8e8092f0090535a8cf9ae95193912216c0b1c1a6c2b1293399eb88beea02012a38fd5b8f89addec320e173
@@ -19,17 +19,32 @@ Metrics/CyclomaticComplexity:
19
19
  Max: 10
20
20
  Metrics/PerceivedComplexity:
21
21
  Max: 10
22
+ Metrics/BlockLength:
23
+ Enabled: false
22
24
  Documentation:
23
25
  Enabled: false
24
26
  Style/SignalException:
25
27
  EnforcedStyle: only_raise
26
- Style/IndentHash:
28
+ Layout/IndentHash:
27
29
  EnforcedStyle: consistent
28
- Style/IndentArray:
30
+ Layout/IndentArray:
29
31
  EnforcedStyle: consistent
30
- Lint/EndAlignment:
31
- AlignWith: variable
32
+ Layout/EndAlignment:
33
+ EnforcedStyleAlignWith: variable
34
+ Lint/InheritException:
35
+ Enabled: false
32
36
  Style/FrozenStringLiteralComment:
33
37
  Enabled: false
34
38
  RSpec/AnyInstance:
35
39
  Enabled: false
40
+ RSpec/NestedGroups:
41
+ Max: 4
42
+ RSpec/ContextWording:
43
+ Prefixes:
44
+ - when
45
+ - with
46
+ - without
47
+ - for
48
+ - as
49
+ RSpec/MultipleExpectations:
50
+ Max: 2
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.2.6
5
- - 2.3.3
6
- - 2.4.0
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
7
8
  env:
8
9
  -
9
10
  - ACTIVE_RECORD_VERSION=4.0.0
@@ -12,16 +13,21 @@ env:
12
13
  - ACTIVE_RECORD_VERSION=5.0.0
13
14
  matrix:
14
15
  allow_failures:
15
- - rvm: 2.4.0
16
+ - rvm: 2.4
16
17
  env: ACTIVE_RECORD_VERSION=4.0.0
17
- - rvm: 2.4.0
18
+ - rvm: 2.4
19
+ env: ACTIVE_RECORD_VERSION=4.1.0
20
+ - rvm: 2.5
21
+ env: ACTIVE_RECORD_VERSION=4.0.0
22
+ - rvm: 2.5
18
23
  env: ACTIVE_RECORD_VERSION=4.1.0
19
- cache: bundler
20
24
  before_install:
21
25
  - gem update --system
22
26
  - gem --version
23
- - gem update bundler
24
- - bundler --version
27
+ install:
28
+ - gem install bundler
29
+ - bundle --version
30
+ - bundle install --jobs=3 --retry=3
25
31
  script:
26
32
  - 'bundle exec rake'
27
33
  notifications:
data/README.md CHANGED
@@ -91,7 +91,7 @@ class Foo < ActiveRecord::Base
91
91
  acts_as_hashids alphabet: '0123456789uvwxyz'
92
92
  end
93
93
 
94
- Foo3.create(id: 1).to_param
94
+ Foo.create(id: 1).to_param
95
95
  # => "4xw8zwyv"
96
96
  ```
97
97
 
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ require 'rubocop/rake_task'
7
7
  RuboCop::RakeTask.new
8
8
 
9
9
  task(:default).clear
10
- task default: [:spec, :rubocop]
10
+ task default: %i[spec rubocop]
@@ -1,5 +1,4 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'acts_as_hashids/version'
5
4
 
@@ -20,17 +19,17 @@ Gem::Specification.new do |spec|
20
19
  spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
20
  spec.require_paths = ['lib']
22
21
 
23
- spec.required_ruby_version = ['>= 2.2.2', '< 2.5']
22
+ spec.required_ruby_version = ['>= 2.2.2', '< 2.6']
24
23
 
25
- spec.add_runtime_dependency 'hashids', '~> 1.0'
26
24
  spec.add_runtime_dependency 'activerecord', '>= 4.0', '< 6.0'
25
+ spec.add_runtime_dependency 'hashids', '~> 1.0'
27
26
 
27
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5'
28
+ spec.add_development_dependency 'coveralls', '~> 0.8'
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'rspec', '~> 3.0'
30
- spec.add_development_dependency 'sqlite3', '~> 1.3'
31
- spec.add_development_dependency 'rubocop', '= 0.37.2'
32
- spec.add_development_dependency 'rubocop-rspec', '= 1.4.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.54.0'
32
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.24.0'
33
33
  spec.add_development_dependency 'simplecov', '~> 0.11'
34
- spec.add_development_dependency 'coveralls', '~> 0.8'
35
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5'
34
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
36
35
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsHashids
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.1.6'.freeze
3
3
  end
@@ -31,31 +31,33 @@ RSpec.describe ActsAsHashids::Core do
31
31
  end
32
32
 
33
33
  describe '.find' do
34
- subject { CoreFoo }
34
+ subject(:model) { CoreFoo }
35
+
35
36
  let!(:foo1) { CoreFoo.create }
36
37
  let!(:foo2) { CoreFoo.create }
38
+
37
39
  context 'for single argument' do
38
40
  it 'decodes hash id and returns the record' do
39
- expect(subject.find(foo1.to_param)).to eq foo1
41
+ expect(model.find(foo1.to_param)).to eq foo1
40
42
  end
41
43
  context 'with unexisting hash id' do
42
44
  it 'raises an exception' do
43
- expect { subject.find('GXbMabNA') }.to raise_error(
45
+ expect { model.find('GXbMabNA') }.to raise_error(
44
46
  ActiveRecord::RecordNotFound, "Couldn't find CoreFoo with 'id'=\"GXbMabNA\""
45
47
  )
46
48
  end
47
49
  end
48
50
  it 'returns the record when finding by string id' do
49
- expect(subject.find(foo1.id.to_s)).to eq foo1
51
+ expect(model.find(foo1.id.to_s)).to eq foo1
50
52
  end
51
53
  end
52
54
  context 'for multiple arguments' do
53
55
  it 'decodes hash id and returns the record' do
54
- expect(subject.find([foo1.to_param, foo2.to_param])).to eq [foo1, foo2]
56
+ expect(model.find([foo1.to_param, foo2.to_param])).to eq [foo1, foo2]
55
57
  end
56
58
  context 'with unexisting hash id' do
57
59
  it 'raises an exception' do
58
- expect { subject.find(%w(GXbMabNA ePQgabdg)) }.to raise_error(
60
+ expect { model.find(%w[GXbMabNA ePQgabdg]) }.to raise_error(
59
61
  ActiveRecord::RecordNotFound,
60
62
  "Couldn't find all CoreFoos with 'id': (\"GXbMabNA\", \"ePQgabdg\") (found 1 results, but was looking for 2)"
61
63
  )
@@ -64,49 +66,59 @@ RSpec.describe ActsAsHashids::Core do
64
66
  end
65
67
  context 'as ActiveRecord_Relation' do
66
68
  it 'decodes hash id and returns the record' do
67
- expect(subject.where(nil).find(foo1.to_param)).to eq foo1
69
+ expect(model.where(nil).find(foo1.to_param)).to eq foo1
68
70
  end
69
71
  end
70
72
  context 'as ActiveRecord_Associations_CollectionProxy' do
71
- let!(:bar3) { CoreBar.create core_foo: foo1 }
72
- let!(:bar4) { CoreBar.create core_foo: foo1 }
73
+ let(:bar3) { CoreBar.create core_foo: foo1 }
74
+ let(:bar4) { CoreBar.create core_foo: foo1 }
75
+
76
+ before do
77
+ bar3
78
+ bar4
79
+ end
80
+
73
81
  it 'decodes hash id and returns the record' do
74
82
  expect(foo1.core_bars.find(bar3.to_param)).to eq bar3
75
83
  end
76
84
  context 'without arguments' do
77
85
  it 'delegates to detect method' do
78
- expect(foo1.core_bars).to receive(:detect).once.and_call_original
86
+ allow(foo1.core_bars).to receive(:detect).once.and_call_original
79
87
  expect(foo1.core_bars.find { |bar| bar == bar3 }).to eq bar3
88
+ expect(foo1.core_bars).to have_received(:detect).once
80
89
  end
81
90
  end
82
91
  end
83
- context 'reloaded' do
84
- subject { CoreFoo.create }
92
+ context 'when reloaded' do
93
+ subject(:model) { CoreFoo.create }
94
+
85
95
  it 'decodes hash id and returns the record' do
86
96
  expect do
87
- subject.reload
97
+ model.reload
88
98
  end.not_to raise_error
89
99
  end
90
100
  end
91
101
  end
92
102
  describe '.with_hashids' do
93
- subject { CoreFoo }
103
+ subject(:model) { CoreFoo }
104
+
94
105
  let!(:foo1) { CoreFoo.create }
95
106
  let!(:foo2) { CoreFoo.create }
107
+
96
108
  it 'decodes hash id and returns the record' do
97
- expect(subject.with_hashids([foo1.to_param, foo2.to_param]).all).to eq [foo1, foo2]
109
+ expect(model.with_hashids([foo1.to_param, foo2.to_param]).all).to eq [foo1, foo2]
98
110
  end
99
111
  context 'with invalid hash id' do
100
112
  it 'raises an exception' do
101
- expect { subject.with_hashids('@').all }.to raise_error(ActsAsHashids::Exception, 'Decode error: ["@"]')
113
+ expect { model.with_hashids('@').all }.to raise_error(ActsAsHashids::Exception, 'Decode error: ["@"]')
102
114
  end
103
115
  end
104
116
  end
105
117
  describe '#to_param' do
106
- subject { CoreFoo.create }
118
+ subject(:model) { CoreFoo.create id: 5 }
119
+
107
120
  it 'returns hash id' do
108
- allow(subject).to receive(:id).and_return 5
109
- expect(subject.to_param).to eq 'GXbMabNA'
121
+ expect(model.to_param).to eq 'GXbMabNA'
110
122
  end
111
123
  end
112
124
  end
@@ -28,46 +28,53 @@ RSpec.describe ActsAsHashids::Methods do
28
28
  end
29
29
 
30
30
  describe '.hashids_secret' do
31
- subject { create_model 'MethodsFoo' }
31
+ subject(:model) { create_model 'MethodsFoo' }
32
+
32
33
  it 'returns the class name' do
33
- expect(subject.hashids_secret).to eq 'MethodsFoo'
34
+ expect(model.hashids_secret).to eq 'MethodsFoo'
34
35
  end
35
36
  context 'for STI' do
36
- let!(:bar) { create_model 'MethodsBar' }
37
- subject { create_model 'MethodsFoo', base: MethodsBar }
37
+ subject(:model) { create_model 'MethodsFoo', base: MethodsBar }
38
+
38
39
  it 'returns the base class name' do
39
- expect(subject.hashids_secret).to eq 'MethodsBar'
40
+ create_model 'MethodsBar'
41
+ expect(model.hashids_secret).to eq 'MethodsBar'
40
42
  end
41
43
  end
42
44
  context 'with custom secret' do
43
- subject { create_model 'MethodsFoo', secret: '^_^' }
45
+ subject(:model) { create_model 'MethodsFoo', secret: '^_^' }
46
+
44
47
  it 'returns the custom secret' do
45
- expect(subject.hashids_secret).to eq '^_^'
48
+ expect(model.hashids_secret).to eq '^_^'
46
49
  end
47
50
  context 'with executable secret' do
48
- subject { create_model 'MethodsFoo', secret: -> { "#{self.name} ^_^" } }
51
+ subject(:model) { create_model 'MethodsFoo', secret: -> { "#{name} ^_^" } }
52
+
49
53
  it 'returns the custom secret' do
50
- expect(subject.hashids_secret).to eq 'MethodsFoo ^_^'
54
+ expect(model.hashids_secret).to eq 'MethodsFoo ^_^'
51
55
  end
52
56
  end
53
57
  end
54
58
  end
55
59
 
56
60
  describe '.hashids' do
57
- subject { create_model 'MethodsFoo' }
61
+ subject(:model) { create_model 'MethodsFoo' }
62
+
58
63
  it 'returns the hashids instance' do
59
- expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8).encode(1)
64
+ expect(model.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8).encode(1)
60
65
  end
61
66
  context 'with custom length' do
62
- subject { create_model 'MethodsFoo', length: 16 }
67
+ subject(:model) { create_model 'MethodsFoo', length: 16 }
68
+
63
69
  it 'returns the hashids instance' do
64
- expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 16).encode(1)
70
+ expect(model.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 16).encode(1)
65
71
  end
66
72
  end
67
73
  context 'with custom alphabet' do
68
- subject { create_model 'MethodsFoo', alphabet: '1234567890abcdef' }
74
+ subject(:model) { create_model 'MethodsFoo', alphabet: '1234567890abcdef' }
75
+
69
76
  it 'returns the hashids instance' do
70
- expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8, '1234567890abcdef').encode(1)
77
+ expect(model.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8, '1234567890abcdef').encode(1)
71
78
  end
72
79
  end
73
80
  end
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
2
 
3
3
  # Test Coverage
4
4
  require 'codeclimate-test-reporter'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_hashids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - dtaniwaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2018-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: hashids
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activerecord
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -45,117 +31,131 @@ dependencies:
45
31
  - !ruby/object:Gem::Version
46
32
  version: '6.0'
47
33
  - !ruby/object:Gem::Dependency
48
- name: rake
34
+ name: hashids
49
35
  requirement: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - "~>"
52
38
  - !ruby/object:Gem::Version
53
- version: '10.0'
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: codeclimate-test-reporter
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.5'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '10.0'
60
+ version: '0.5'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rspec
62
+ name: coveralls
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.0'
67
+ version: '0.8'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '3.0'
74
+ version: '0.8'
75
75
  - !ruby/object:Gem::Dependency
76
- name: sqlite3
76
+ name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '1.3'
81
+ version: '10.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '1.3'
88
+ version: '10.0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: rubocop
90
+ name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '='
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 0.37.2
95
+ version: '3.0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - '='
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 0.37.2
102
+ version: '3.0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: rubocop-rspec
104
+ name: rubocop
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - '='
107
+ - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: 1.4.0
109
+ version: 0.54.0
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - '='
114
+ - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: 1.4.0
116
+ version: 0.54.0
117
117
  - !ruby/object:Gem::Dependency
118
- name: simplecov
118
+ name: rubocop-rspec
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '0.11'
123
+ version: 1.24.0
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '0.11'
130
+ version: 1.24.0
131
131
  - !ruby/object:Gem::Dependency
132
- name: coveralls
132
+ name: simplecov
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0.8'
137
+ version: '0.11'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0.8'
144
+ version: '0.11'
145
145
  - !ruby/object:Gem::Dependency
146
- name: codeclimate-test-reporter
146
+ name: sqlite3
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '0.5'
151
+ version: '1.3'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '0.5'
158
+ version: '1.3'
159
159
  description: Use Youtube-Like ID in ActiveRecord seamlessly.
160
160
  email:
161
161
  - daisuketaniwaki@gmail.com
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
201
  version: 2.2.2
202
202
  - - "<"
203
203
  - !ruby/object:Gem::Version
204
- version: '2.5'
204
+ version: '2.6'
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  version: '0'
210
210
  requirements: []
211
211
  rubyforge_project:
212
- rubygems_version: 2.6.8
212
+ rubygems_version: 2.7.6
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: Use Youtube-Like ID in ActiveRecord seamlessly.