acts_as_hashed 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5526f241d84691664bb38299149aa9ec434c8c1c
4
+ data.tar.gz: 0c6d06978022f6c304e440ff2f052f6eebffb00c
5
+ SHA512:
6
+ metadata.gz: 2bf2c050e6e9f2dc88a317ce42877b90121c8bd994a8f430dc0bdb9965ab055f8653c6a5f7a86fd06982266855caf6200c8c6bd1bf1d83c2422698cd335f6ac4
7
+ data.tar.gz: c2e1cee5821839d64708520cdd389065b6a0f7e98290de80c8109f3119cd0a092734158d153ac4defd5d59f4b60477ba8e2cebd6acef861ea7754483187fe63b
@@ -0,0 +1 @@
1
+ acts_as_hashed
@@ -0,0 +1 @@
1
+ 1.9.3
data/README.md CHANGED
@@ -18,16 +18,22 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- #### Run your migrations for the desired models
21
+ #### Create your migrations for the desired models
22
+
23
+ ```bash
24
+ $ rails g migration AddHashedCodeToOrders hashed_code:string
25
+ ```
26
+
27
+ or
22
28
 
23
29
  ```ruby
24
- class AddHashedCodeToSeller < ActiveRecord::Migration
30
+ class AddHashedCodeToOrders < ActiveRecord::Migration
25
31
  def self.up
26
- add_column :sellers, :hashed_code, :string
32
+ add_column :orders, :hashed_code, :string
27
33
  end
28
34
 
29
35
  def self.down
30
- remove_column :sellers, :hashed_code, :string
36
+ remove_column :orders, :hashed_code, :string
31
37
  end
32
38
  end
33
39
  ```
@@ -37,9 +43,13 @@ end
37
43
  #### In your model:
38
44
 
39
45
  ```ruby
40
- class Seller < ActiveRecord::Base
46
+ class Order < ActiveRecord::Base
41
47
  acts_as_hashed
42
48
 
49
+ def to_param
50
+ hashed_code
51
+ end
52
+
43
53
  ...
44
54
  end
45
55
  ```
@@ -47,7 +57,7 @@ end
47
57
  or you can overwrite the method that will generate the hash.
48
58
 
49
59
  ```ruby
50
- class Seller < ActiveRecord::Base
60
+ class Order < ActiveRecord::Base
51
61
  acts_as_hashed
52
62
 
53
63
  class << self
@@ -58,6 +68,12 @@ class Seller < ActiveRecord::Base
58
68
  end
59
69
  ```
60
70
 
71
+ If you are adding acts_as_hashed after having some records on your database you need too run the code above to update the records:
72
+
73
+ ```ruby
74
+ Order.update_missing_hashed_code
75
+ ```
76
+
61
77
  ## Contributing
62
78
 
63
79
  1. Fork it
@@ -65,3 +81,12 @@ end
65
81
  3. Commit your changes (`git commit -am 'Added some feature'`)
66
82
  4. Push to the branch (`git push origin my-new-feature`)
67
83
  5. Create new Pull Request
84
+
85
+ ## Credits
86
+
87
+ ActsAsHashed is maintained and funded by [HE:labs](http://helabs.com.br/opensource/).
88
+ Thank you to all the [contributors](https://github.com/Helabs/acts_as_hashed/graphs/contributors).
89
+
90
+ ## License
91
+
92
+ ActsAsHashed is Copyright © 2012-2014 HE:labs. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile CHANGED
@@ -1,2 +1,15 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ spec.rcov = true
13
+ end
14
+
15
+ task :default => :spec
@@ -19,6 +19,12 @@ module ActsAsHashed
19
19
  def hashed_code_exists?(hashed_code)
20
20
  where(:hashed_code => hashed_code).any?
21
21
  end
22
+
23
+ def update_missing_hashed_code
24
+ where(hashed_code: nil).find_each do |record|
25
+ record.update_column(:hashed_code, friendly_token)
26
+ end
27
+ end
22
28
  end
23
29
 
24
30
  def set_hashed_code
@@ -1,3 +1,3 @@
1
1
  module ActsAsHashed
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -29,36 +29,47 @@ describe ActsAsHashed do
29
29
  before(:each) do
30
30
  clean_database!
31
31
  end
32
- context "new record" do
33
- let(:model) { SomeModel.new }
34
- it "should save hashed code" do
35
- SomeModel.stub(:friendly_token).and_return('new-hashed-code-here')
36
- expect {
37
- model.save!
38
- }.to change(model, :hashed_code).from(nil).to('new-hashed-code-here')
39
- end
40
- end
41
- describe "persisted record" do
42
- let(:model) do
43
- model = SomeModel.new
44
- model.save!
45
- model
32
+ describe :save do
33
+ context "new record" do
34
+ let(:model) { SomeModel.new }
35
+ it "should save hashed code" do
36
+ SomeModel.stub(:friendly_token).and_return('new-hashed-code-here')
37
+ expect {
38
+ model.save!
39
+ }.to change(model, :hashed_code).from(nil).to('new-hashed-code-here')
40
+ end
46
41
  end
47
- it "should save hashed code" do
48
- SomeModel.stub(:friendly_token).and_return('new-hashed-code-here')
49
- expect {
42
+ describe "persisted record" do
43
+ let(:model) do
44
+ model = SomeModel.new
50
45
  model.save!
51
- }.to_not change(model, :hashed_code)
46
+ model
47
+ end
48
+ it "should save hashed code" do
49
+ SomeModel.stub(:friendly_token).and_return('new-hashed-code-here')
50
+ expect {
51
+ model.save!
52
+ }.to_not change(model, :hashed_code)
53
+ end
54
+ end
55
+ context "overwrite friendly_token" do
56
+ let!(:model) do
57
+ model = OverwritedModel.new
58
+ model.save
59
+ model
60
+ end
61
+ it "should have hashed_code with lenght 10" do
62
+ model.hashed_code.length.should == 10
63
+ end
52
64
  end
53
65
  end
54
- context "overwrite friendly_token" do
66
+ describe :update_missing_hashed_code do
55
67
  let!(:model) do
56
- model = OverwritedModel.new
68
+ model = SomeModel.new
57
69
  model.save
58
- model
59
- end
60
- it "should have hashed_code with lenght 10" do
61
- model.hashed_code.length.should == 10
70
+ model.update_column(:hashed_code, nil)
71
+ model.reload
62
72
  end
73
+ it { expect { SomeModel.update_missing_hashed_code }.to change { model.reload.hashed_code }.from(nil) }
63
74
  end
64
75
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_hashed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rodrigo Pinto
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-05 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - '='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - '='
28
25
  - !ruby/object:Gem::Version
@@ -30,33 +27,29 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activerecord
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 3.0.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 3.0.0
62
55
  description: ActsAsHashed is helpful to set a hash_code column based on SecureRandom.hex(16).
@@ -68,7 +61,8 @@ extra_rdoc_files: []
68
61
  files:
69
62
  - .gitignore
70
63
  - .rspec
71
- - .rvmrc
64
+ - .ruby-gemset
65
+ - .ruby-version
72
66
  - Gemfile
73
67
  - LICENSE
74
68
  - README.md
@@ -81,27 +75,26 @@ files:
81
75
  - spec/spec_helper.rb
82
76
  homepage: ''
83
77
  licenses: []
78
+ metadata: {}
84
79
  post_install_message:
85
80
  rdoc_options: []
86
81
  require_paths:
87
82
  - lib
88
83
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
84
  requirements:
91
- - - ! '>='
85
+ - - '>='
92
86
  - !ruby/object:Gem::Version
93
87
  version: '0'
94
88
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
89
  requirements:
97
- - - ! '>='
90
+ - - '>='
98
91
  - !ruby/object:Gem::Version
99
92
  version: '0'
100
93
  requirements: []
101
94
  rubyforge_project:
102
- rubygems_version: 1.8.24
95
+ rubygems_version: 2.0.6
103
96
  signing_key:
104
- specification_version: 3
97
+ specification_version: 4
105
98
  summary: SecureRandom hex generator for hashed_code column.
106
99
  test_files:
107
100
  - spec/acts_as_hashed_spec.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm --create 1.9.3-p125@acts_as_hashed