acts_as_hashids 0.1.3 → 0.1.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: 8382391d902cd40f0456018a39049f170e031698
4
- data.tar.gz: 76c9d57e2098e71319e53f9207f739d971cbe57c
3
+ metadata.gz: 7e73bc8dc01050b7cd4e73c8f66d41f9490505dc
4
+ data.tar.gz: e45de056b6215bfcf51ff03872a15468430f08da
5
5
  SHA512:
6
- metadata.gz: b81058339a4bdf54f29f0a8985e4f725837bb85eb991e4d7c13ce40e69bffdd607070b4a730a21947cb84c9e8e9ea1fc0148907ec540a193ef5c11457db2975c
7
- data.tar.gz: fa7d5efc9250e544d89d09ced677b62adefd05e2e472d19194e724aede5b13d3323e59d818261ed9687b02136dde0baa3bc5da6130bcd023e3fd3ee9c48e9f23
6
+ metadata.gz: 418e43334a2518847872d4cfa12ddae479d26d6a604edf65ea4b042bdde73150dd732d17fd5112b8d1b3657870f66c7364157c48566113e09dc42d674d5c800f
7
+ data.tar.gz: 2304ac53bd1c53ce1f00f8eb2fb16d5f172dd64e7f4cceaf73974af0057312b836499089aca832f2ff5824210062c076ceb0d820bba1e150c7f56c4cbf728ee8
data/.travis.yml CHANGED
@@ -1,21 +1,28 @@
1
1
  language: ruby
2
- sudo: required
2
+ sudo: false
3
3
  rvm:
4
- - 2.2
5
- - 2.3.0
4
+ - 2.2.6
5
+ - 2.3.3
6
+ - 2.4.0
6
7
  env:
7
8
  -
8
- - ACTIVE_RECORD_VERSION=4.0
9
- - ACTIVE_RECORD_VERSION=4.1
10
- - ACTIVE_RECORD_VERSION=4.2
11
- - ACTIVE_RECORD_VERSION=5.0.0.beta4
9
+ - ACTIVE_RECORD_VERSION=4.0.0
10
+ - ACTIVE_RECORD_VERSION=4.1.0
11
+ - ACTIVE_RECORD_VERSION=4.2.0
12
+ - ACTIVE_RECORD_VERSION=5.0.0
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: 2.4.0
16
+ env: ACTIVE_RECORD_VERSION=4.0.0
17
+ - rvm: 2.4.0
18
+ env: ACTIVE_RECORD_VERSION=4.1.0
12
19
  cache: bundler
13
- install:
14
- - 'gem install bundler'
15
- - 'bundle install --jobs=3 --retry=3'
20
+ before_install:
21
+ - gem update --system
22
+ - gem --version
23
+ - gem update bundler
24
+ - bundler --version
16
25
  script:
17
26
  - 'bundle exec rake'
18
- services:
19
- - docker
20
27
  notifications:
21
28
  email: false
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', "~> #{ENV['ACTIVE_RECORD_VERSION']}" if ENV['ACTIVE_RECORD_VERSION'].to_s != ''
4
-
5
- # Specify your gem's dependencies in acts_as_hashids.gemspec
6
3
  gemspec
4
+
5
+ gem 'gem-release'
6
+ gem 'pry'
7
+
8
+ gem 'activerecord', "~> #{ENV['ACTIVE_RECORD_VERSION']}" if ENV['ACTIVE_RECORD_VERSION'].to_s != ''
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Coverage Status][cov-image]][cov-link]
6
6
  [![Code Climate][gpa-image]][gpa-link]
7
7
 
8
- Use [Hashids](https://github.com/peterhellberg/hashids.rb) in ActiveRecord effectively.
8
+ Use [Hashids](https://github.com/peterhellberg/hashids.rb) (a.k.a. Youtube-Like ID) in ActiveRecord effectively.
9
9
 
10
10
  ## Installation
11
11
 
@@ -6,6 +6,7 @@ require 'acts_as_hashids/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'acts_as_hashids'
8
8
  spec.version = ActsAsHashids::VERSION
9
+ spec.platform = Gem::Platform::RUBY
9
10
  spec.authors = ['dtaniwaki']
10
11
  spec.email = ['daisuketaniwaki@gmail.com']
11
12
 
@@ -15,14 +16,15 @@ Gem::Specification.new do |spec|
15
16
  spec.license = 'MIT'
16
17
 
17
18
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = 'exe'
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
21
  spec.require_paths = ['lib']
21
22
 
22
- spec.add_dependency 'hashids', '~> 1.0'
23
- spec.add_dependency 'activerecord', '>= 4.0'
23
+ spec.required_ruby_version = ['>= 2.2.2', '< 2.5']
24
+
25
+ spec.add_runtime_dependency 'hashids', '~> 1.0'
26
+ spec.add_runtime_dependency 'activerecord', '>= 4.0', '< 6.0'
24
27
 
25
- spec.add_development_dependency 'bundler', '~> 1.11'
26
28
  spec.add_development_dependency 'rake', '~> 10.0'
27
29
  spec.add_development_dependency 'rspec', '~> 3.0'
28
30
  spec.add_development_dependency 'sqlite3', '~> 1.3'
@@ -1,3 +1,3 @@
1
1
  module ActsAsHashids
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActsAsHashids::Core do
4
+ around :context do |block|
5
+ m = ActiveRecord::Migration.new
6
+ m.verbose = false
7
+ m.create_table :core_foos, force: true do |t|
8
+ end
9
+ m.create_table :core_bars, force: true do |t|
10
+ t.integer :core_foo_id, index: true
11
+ end
12
+ begin
13
+ block.call
14
+ ensure
15
+ m.drop_table :core_foos
16
+ m.drop_table :core_bars
17
+ end
18
+ end
19
+
20
+ class Base < ActiveRecord::Base
21
+ self.abstract_class = true
22
+ acts_as_hashids
23
+ end
24
+
25
+ class CoreFoo < Base
26
+ has_many :core_bars
27
+ end
28
+
29
+ class CoreBar < Base
30
+ belongs_to :core_foo
31
+ end
32
+
33
+ describe '.find' do
34
+ subject { CoreFoo }
35
+ let!(:foo1) { CoreFoo.create }
36
+ let!(:foo2) { CoreFoo.create }
37
+ context 'for single argument' do
38
+ it 'decodes hash id and returns the record' do
39
+ expect(subject.find(foo1.to_param)).to eq foo1
40
+ end
41
+ context 'with unexisting hash id' do
42
+ it 'raises an exception' do
43
+ expect { subject.find('GXbMabNA') }.to raise_error(
44
+ ActiveRecord::RecordNotFound, "Couldn't find CoreFoo with 'id'=\"GXbMabNA\""
45
+ )
46
+ end
47
+ end
48
+ end
49
+ context 'for multiple arguments' do
50
+ it 'decodes hash id and returns the record' do
51
+ expect(subject.find([foo1.to_param, foo2.to_param])).to eq [foo1, foo2]
52
+ end
53
+ context 'with unexisting hash id' do
54
+ it 'raises an exception' do
55
+ expect { subject.find(%w(GXbMabNA ePQgabdg)) }.to raise_error(
56
+ ActiveRecord::RecordNotFound,
57
+ "Couldn't find all CoreFoos with 'id': (\"GXbMabNA\", \"ePQgabdg\") (found 1 results, but was looking for 2)"
58
+ )
59
+ end
60
+ end
61
+ end
62
+ context 'as ActiveRecord_Relation' do
63
+ it 'decodes hash id and returns the record' do
64
+ expect(subject.where(nil).find(foo1.to_param)).to eq foo1
65
+ end
66
+ end
67
+ context 'as ActiveRecord_Associations_CollectionProxy' do
68
+ let!(:bar3) { CoreBar.create core_foo: foo1 }
69
+ let!(:bar4) { CoreBar.create core_foo: foo1 }
70
+ it 'decodes hash id and returns the record' do
71
+ expect(foo1.core_bars.find(bar3.to_param)).to eq bar3
72
+ end
73
+ context 'without arguments' do
74
+ it 'delegates to detect method' do
75
+ expect(foo1.core_bars).to receive(:detect).once.and_call_original
76
+ expect(foo1.core_bars.find { |bar| bar == bar3 }).to eq bar3
77
+ end
78
+ end
79
+ end
80
+ context 'reloaded' do
81
+ subject { CoreFoo.create }
82
+ it 'decodes hash id and returns the record' do
83
+ expect do
84
+ subject.reload
85
+ end.not_to raise_error
86
+ end
87
+ end
88
+ end
89
+ describe '.with_hashids' do
90
+ subject { CoreFoo }
91
+ let!(:foo1) { CoreFoo.create }
92
+ let!(:foo2) { CoreFoo.create }
93
+ it 'decodes hash id and returns the record' do
94
+ expect(subject.with_hashids([foo1.to_param, foo2.to_param]).all).to eq [foo1, foo2]
95
+ end
96
+ context 'with invalid hash id' do
97
+ it 'raises an exception' do
98
+ expect { subject.with_hashids('@').all }.to raise_error(ActsAsHashids::Exception, 'Decode error: ["@"]')
99
+ end
100
+ end
101
+ end
102
+ describe '#to_param' do
103
+ subject { CoreFoo.create }
104
+ it 'returns hash id' do
105
+ allow(subject).to receive(:id).and_return 5
106
+ expect(subject.to_param).to eq 'GXbMabNA'
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe ActsAsHashids::Methods do
4
+ around :context do |block|
5
+ m = ActiveRecord::Migration.new
6
+ m.verbose = false
7
+ m.create_table :methods_foos, force: true do |t|
8
+ end
9
+ m.create_table :methods_bars, force: true do |t|
10
+ t.string :type
11
+ end
12
+ begin
13
+ block.call
14
+ ensure
15
+ m.drop_table :methods_foos
16
+ m.drop_table :methods_bars
17
+ end
18
+ end
19
+
20
+ def create_model(name, options = {})
21
+ base = options[:base] || ActiveRecord::Base
22
+ Object.send :remove_const, name if Object.const_defined?(name)
23
+ klass = Class.new(base) do
24
+ acts_as_hashids options
25
+ end
26
+ Object.const_set name, klass
27
+ Object.const_get name
28
+ end
29
+
30
+ describe '.hashids_secret' do
31
+ subject { create_model 'MethodsFoo' }
32
+ it 'returns the class name' do
33
+ expect(subject.hashids_secret).to eq 'MethodsFoo'
34
+ end
35
+ context 'for STI' do
36
+ let!(:bar) { create_model 'MethodsBar' }
37
+ subject { create_model 'MethodsFoo', base: MethodsBar }
38
+ it 'returns the base class name' do
39
+ expect(subject.hashids_secret).to eq 'MethodsBar'
40
+ end
41
+ end
42
+ context 'with custom secret' do
43
+ subject { create_model 'MethodsFoo', secret: '^_^' }
44
+ it 'returns the custom secret' do
45
+ expect(subject.hashids_secret).to eq '^_^'
46
+ end
47
+ context 'with executable secret' do
48
+ subject { create_model 'MethodsFoo', secret: -> { "#{self.name} ^_^" } }
49
+ it 'returns the custom secret' do
50
+ expect(subject.hashids_secret).to eq 'MethodsFoo ^_^'
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '.hashids' do
57
+ subject { create_model 'MethodsFoo' }
58
+ it 'returns the hashids instance' do
59
+ expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8).encode(1)
60
+ end
61
+ context 'with custom length' do
62
+ subject { create_model 'MethodsFoo', length: 16 }
63
+ it 'returns the hashids instance' do
64
+ expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 16).encode(1)
65
+ end
66
+ end
67
+ context 'with custom alphabet' do
68
+ subject { create_model 'MethodsFoo', alphabet: '1234567890abcdef' }
69
+ it 'returns the hashids instance' do
70
+ expect(subject.hashids.encode(1)).to eq Hashids.new('MethodsFoo', 8, '1234567890abcdef').encode(1)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActsAsHashids do
4
+ it 'has a version number' do
5
+ expect(ActsAsHashids::VERSION).not_to be nil
6
+ end
7
+ it 'defines acts_as_hashids method in ActiveRecord::Base' do
8
+ expect(ActiveRecord::Base).to respond_to(:acts_as_hashids)
9
+ end
10
+ end
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # Test Coverage
4
+ require 'codeclimate-test-reporter'
5
+ require 'coveralls'
6
+ require 'simplecov'
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
+ Coveralls::SimpleCov::Formatter,
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ CodeClimate::TestReporter::Formatter
11
+ ])
12
+ SimpleCov.minimum_coverage 50
13
+ SimpleCov.start
14
+
15
+ require 'active_record'
16
+
17
+ ActiveRecord::Base.establish_connection(
18
+ adapter: 'sqlite3',
19
+ host: 'localhost',
20
+ database: 'test.db'
21
+ )
22
+
23
+ require 'acts_as_hashids'
24
+
25
+ RSpec.configure do |config|
26
+ config.expect_with :rspec do |expectations|
27
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
28
+ end
29
+
30
+ config.mock_with :rspec do |mocks|
31
+ mocks.verify_partial_doubles = true
32
+ end
33
+
34
+ config.default_formatter = 'doc' if config.files_to_run.one?
35
+ config.profile_examples = 10
36
+ config.order = :random
37
+ Kernel.srand config.seed
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_hashids
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dtaniwaki
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashids
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,20 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '4.0'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
44
+ - - "<"
46
45
  - !ruby/object:Gem::Version
47
- version: '1.11'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.11'
46
+ version: '6.0'
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: rake
57
49
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +159,9 @@ dependencies:
167
159
  description: Use Hashids in ActiveRecord effectively.
168
160
  email:
169
161
  - daisuketaniwaki@gmail.com
170
- executables: []
162
+ executables:
163
+ - console
164
+ - setup
171
165
  extensions: []
172
166
  extra_rdoc_files: []
173
167
  files:
@@ -187,6 +181,10 @@ files:
187
181
  - lib/acts_as_hashids/methods.rb
188
182
  - lib/acts_as_hashids/railtie.rb
189
183
  - lib/acts_as_hashids/version.rb
184
+ - spec/acts_as_hashids/core_spec.rb
185
+ - spec/acts_as_hashids/methods_spec.rb
186
+ - spec/acts_as_hashids_spec.rb
187
+ - spec/spec_helper.rb
190
188
  homepage: https://github.com/dtaniwaki/acts_as_hashids
191
189
  licenses:
192
190
  - MIT
@@ -199,7 +197,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
197
  requirements:
200
198
  - - ">="
201
199
  - !ruby/object:Gem::Version
202
- version: '0'
200
+ version: 2.2.2
201
+ - - "<"
202
+ - !ruby/object:Gem::Version
203
+ version: '2.5'
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  requirements:
205
206
  - - ">="
@@ -207,9 +208,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
208
  version: '0'
208
209
  requirements: []
209
210
  rubyforge_project:
210
- rubygems_version: 2.5.1
211
+ rubygems_version: 2.6.8
211
212
  signing_key:
212
213
  specification_version: 4
213
214
  summary: Hashids in ActiveRecord effectively.
214
- test_files: []
215
- has_rdoc:
215
+ test_files:
216
+ - spec/acts_as_hashids/core_spec.rb
217
+ - spec/acts_as_hashids/methods_spec.rb
218
+ - spec/acts_as_hashids_spec.rb
219
+ - spec/spec_helper.rb