association_callbacks 1.0.0 → 1.0.1

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: 2994cec2c46bbf3f85cf7c87164276185678571a
4
- data.tar.gz: b0e8f30e500e5cacec58cda454647f9a93775fa4
3
+ metadata.gz: 1ce7d38429ce86497d2680a93e8e80134c2779dd
4
+ data.tar.gz: a9910271a2180fffd89d631fd10c45256a30e243
5
5
  SHA512:
6
- metadata.gz: cce917363779bc6b2c8b4fc5ef7524adf7c516bbcb289514276cc76ed5a935cdbac71090d792c9310e8f0140022b6a2d78028f3595c9cde6ef1e4e6ccea9eb42
7
- data.tar.gz: b6e9141678292d4963239b66854236db1d3da84996fe1652b5c8805db2636a8f5eed7d06bcd2e58c08c03f5cafd338f83537edb87851dc11273a45a5c26eb998
6
+ metadata.gz: c640f3b8dc06d37ab974b01ca54bee6e2368fbd8b34b012a8ae37ee094ae00bd4e156407b4a2bbc650ade10831c90711154922731c6df2e174d71f9b7a7a61b6
7
+ data.tar.gz: e1019b36daabb1a199bf16c96313d4852ffa9ac23887604762ef756eb76a98d81b237e14df16511a58b8165652e45d6282aac88eec57538a21658c8f52ce7900
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -9,13 +9,12 @@ Gem::Specification.new do |s|
9
9
  s.description = 'Provides a way to define callbacks of one ActiveRecord model into an associated one'
10
10
  s.license = 'MIT'
11
11
 
12
- s.rubyforge_project = 'association_callbacks'
13
-
14
- s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ s.files = `git ls-files | grep -vE '^(spec/|test/|\\.|Gemfile|Rakefile)'`.split("\n")
16
13
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
14
  s.require_paths = ['lib']
18
15
 
16
+ s.required_ruby_version = '>= 2.0.0'
17
+
19
18
  s.add_dependency 'activerecord', '>= 5.0.0', '< 5.1.0'
20
19
  s.add_dependency 'activesupport', '>= 5.0.0', '< 5.1.0'
21
20
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_callbacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-28 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -137,22 +137,12 @@ executables: []
137
137
  extensions: []
138
138
  extra_rdoc_files: []
139
139
  files:
140
- - ".gitignore"
141
- - ".rspec"
142
- - Gemfile
143
140
  - MIT-LICENSE
144
141
  - README.mdown
145
- - Rakefile
146
142
  - VERSION
147
143
  - association_callbacks.gemspec
148
144
  - lib/association_callbacks.rb
149
145
  - lib/association_callbacks/active_record.rb
150
- - spec/association_callbacks/active_record_spec.rb
151
- - spec/association_callbacks_spec.rb
152
- - spec/mocks/comment.rb
153
- - spec/mocks/post.rb
154
- - spec/spec_helper.rb
155
- - spec/support/bootsrap/database.rb
156
146
  homepage: https://github.com/alexistoulotte/association_callbacks
157
147
  licenses:
158
148
  - MIT
@@ -165,22 +155,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
155
  requirements:
166
156
  - - ">="
167
157
  - !ruby/object:Gem::Version
168
- version: '0'
158
+ version: 2.0.0
169
159
  required_rubygems_version: !ruby/object:Gem::Requirement
170
160
  requirements:
171
161
  - - ">="
172
162
  - !ruby/object:Gem::Version
173
163
  version: '0'
174
164
  requirements: []
175
- rubyforge_project: association_callbacks
176
- rubygems_version: 2.5.1
165
+ rubyforge_project:
166
+ rubygems_version: 2.6.8
177
167
  signing_key:
178
168
  specification_version: 4
179
169
  summary: Callbacks for ActiveRecord associations
180
- test_files:
181
- - spec/association_callbacks/active_record_spec.rb
182
- - spec/association_callbacks_spec.rb
183
- - spec/mocks/comment.rb
184
- - spec/mocks/post.rb
185
- - spec/spec_helper.rb
186
- - spec/support/bootsrap/database.rb
170
+ test_files: []
data/.gitignore DELETED
@@ -1,6 +0,0 @@
1
- .DS_Store
2
- /.bundle/
3
- /.ruby-version
4
- /Gemfile.lock
5
- /pkg/
6
- /spec/test.sqlite3
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --order random
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require 'bundler'
2
- require 'rspec/core/rake_task'
3
-
4
- Bundler::GemHelper.install_tasks
5
-
6
- desc 'Default: runs specs.'
7
- task default: :spec
8
-
9
- desc 'Run all specs in spec directory.'
10
- RSpec::Core::RakeTask.new(:spec)
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AssociationCallbacks::ActiveRecord do
4
-
5
- context 'with has_many relation' do
6
-
7
- it 'invokes callback defines as method' do
8
- post = Post.create!
9
- expect {
10
- Comment.create!(post_id: post.id)
11
- }.to change { post.reload.comments_count }.by(1)
12
- end
13
-
14
- it 'invokes callback defines as method (with one argument)' do
15
- post = Post.create!
16
- expect {
17
- Comment.create!(post: post, created_at: 2.years.ago)
18
- }.to change { post.reload.last_comment_at }.from(nil)
19
- expect(post.last_comment_at.to_i).to be_within(5).of(2.years.ago.to_i)
20
- end
21
-
22
- it 'invokes callback defines as block' do
23
- post = Post.create!
24
- comment = Comment.create!(post: post)
25
- expect {
26
- comment.destroy
27
- }.to change { post.reload.comments_count }.by(-1)
28
- end
29
-
30
- it 'invokes regular callbacks' do
31
- post = Post.new(body: 'this is body', title: 'foo')
32
- expect {
33
- post.save!
34
- }.to change { post.texts }.from(nil).to('foo,this,is,body')
35
- end
36
-
37
- end
38
-
39
- context 'with belongs_to relation' do
40
-
41
- it 'invokes callback defines as method' do
42
- post = Post.create!
43
- comment = post.comments.create!
44
- expect {
45
- post.update_attributes!(title: 'foo')
46
- }.to change { comment.reload.post_updated_at }
47
- expect(comment.post_updated_at.to_i).to be_within(5).of(Time.now.to_i)
48
- end
49
-
50
- it 'invokes callback defines as method (with one argument)' do
51
- post = Post.create!(title: 'foo')
52
- comment = post.comments.create!
53
- expect {
54
- post.update_attributes!(title: 'bar')
55
- }.to change { comment.reload.post.title }.from('foo').to('bar')
56
- end
57
-
58
- it 'invokes callback defines as block' do
59
- post = Post.create!
60
- comment = Comment.create!(post_id: post.id)
61
- expect {
62
- post.destroy
63
- }.to change { comment.reload.orphan_from_id }.from(nil).to(post.id)
64
- end
65
-
66
- it 'invokes regular callbacks' do
67
- post = Post.create!(title: 'foo')
68
- comment = Comment.new(post: post)
69
- expect {
70
- comment.save!
71
- }.to change { comment.post_title }.from(nil).to('foo')
72
- end
73
-
74
- end
75
-
76
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe AssociationCallbacks do
4
-
5
- describe '.version' do
6
-
7
- subject { AssociationCallbacks.version }
8
-
9
- it { should be_a(String) }
10
- it { should match(/^\d+\.\d+(\.\d+)?$/) }
11
-
12
- it 'is freezed' do
13
- expect {
14
- subject.gsub!('.', '#')
15
- }.to raise_error(/can't modify frozen string/i)
16
- end
17
-
18
- end
19
-
20
- end
@@ -1,26 +0,0 @@
1
- class Comment < ActiveRecord::Base
2
-
3
- belongs_to :post, inverse_of: :comments
4
-
5
- after_save :update_post_updated_at, source: :post
6
- before_create :set_post_title
7
- before_save :update_post_title, source: :post
8
- after_destroy source: :post do |comment, post|
9
- comment.update_attributes!(orphan_from_id: post.id)
10
- end
11
-
12
- private
13
-
14
- def set_post_title
15
- self.post_title = post.title
16
- end
17
-
18
- def update_post_title(post)
19
- update_attributes!(post_title: post.title) if post.title_changed?
20
- end
21
-
22
- def update_post_updated_at
23
- update_attributes!(post_updated_at: post.updated_at)
24
- end
25
-
26
- end
data/spec/mocks/post.rb DELETED
@@ -1,23 +0,0 @@
1
- class Post < ActiveRecord::Base
2
-
3
- has_many :comments, inverse_of: :post
4
-
5
- after_create :increment_comments_count, :update_last_comment_at, source: :comments
6
- after_destroy source: :comments do |post|
7
- post.decrement!(:comments_count)
8
- end
9
- before_save do |post|
10
- post.texts = "#{post.title} #{post.body}".strip.split(/\s+/).join(',')
11
- end
12
-
13
- private
14
-
15
- def increment_comments_count
16
- increment!(:comments_count)
17
- end
18
-
19
- def update_last_comment_at(comment)
20
- update_attributes!(last_comment_at: comment.created_at)
21
- end
22
-
23
- end
data/spec/spec_helper.rb DELETED
@@ -1,19 +0,0 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
-
3
- require File.expand_path("#{__dir__}/../lib/association_callbacks")
4
- require 'byebug'
5
-
6
- # Support
7
- Dir["#{__dir__}/support/**/*.rb"].each { |f| require f }
8
-
9
- # Mocks
10
- ActiveSupport::Dependencies.autoload_paths << "#{__dir__}/mocks"
11
-
12
- RSpec.configure do |config|
13
- config.raise_errors_for_deprecations!
14
-
15
- config.before(:each) do
16
- Comment.delete_all
17
- Post.delete_all
18
- end
19
- end
@@ -1,17 +0,0 @@
1
- ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: File.expand_path("#{__dir__}/../../test.sqlite3"), timeout: 5000)
2
-
3
- ActiveRecord::Base.connection.create_table(:comments, force: true) do |t|
4
- t.integer :orphan_from_id
5
- t.datetime :post_updated_at
6
- t.integer :post_id
7
- t.string :post_title
8
- t.timestamps null: false
9
- end
10
- ActiveRecord::Base.connection.create_table(:posts, force: true) do |t|
11
- t.text :body
12
- t.integer :comments_count, default: 0
13
- t.datetime :last_comment_at
14
- t.text :texts
15
- t.string :title
16
- t.timestamps null: false
17
- end