association_callbacks 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2adcf9566d4079e78d62bbe766a3c37580e5ff5
4
+ data.tar.gz: fef9e157819d80e9643ef09ae9e2a29e13dc8c9b
5
+ SHA512:
6
+ metadata.gz: ccbd2e31468e7d36e53f40b06cdc5f592b1903c174cf998bce4894228a929b8b96e7ea547e98388cb98bf438a8f47535d39649013d18cd3f0664b02df9adc963
7
+ data.tar.gz: 92de408d078e737f39676e8d02b7bf8608db05d54fe2f2f59b6282139fb4dfcc37adb178873f7bd8928c2548df7896702007a612b9109610414b723016399742
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
1
  .DS_Store
2
2
  .bundle
3
- .rbenv-version
3
+ .ruby-version
4
4
  pkg/*
5
5
  spec/test.sqlite3
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --colour
2
- --format progress
2
+ --order random
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,89 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- association_callbacks (0.0.2)
4
+ association_callbacks (0.1.0)
5
5
  activerecord (~> 3.2.0)
6
6
  activesupport (~> 3.2.0)
7
7
 
8
8
  GEM
9
- remote: http://rubygems.org/
9
+ remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (3.2.3)
12
- activemodel (= 3.2.3)
13
- activesupport (= 3.2.3)
11
+ activemodel (3.2.13)
12
+ activesupport (= 3.2.13)
14
13
  builder (~> 3.0.0)
15
- erubis (~> 2.7.0)
16
- journey (~> 1.0.1)
17
- rack (~> 1.4.0)
18
- rack-cache (~> 1.2)
19
- rack-test (~> 0.6.1)
20
- sprockets (~> 2.1.2)
21
- activemodel (3.2.3)
22
- activesupport (= 3.2.3)
23
- builder (~> 3.0.0)
24
- activerecord (3.2.3)
25
- activemodel (= 3.2.3)
26
- activesupport (= 3.2.3)
14
+ activerecord (3.2.13)
15
+ activemodel (= 3.2.13)
16
+ activesupport (= 3.2.13)
27
17
  arel (~> 3.0.2)
28
18
  tzinfo (~> 0.3.29)
29
- activesupport (3.2.3)
30
- i18n (~> 0.6)
19
+ activesupport (3.2.13)
20
+ i18n (= 0.6.1)
31
21
  multi_json (~> 1.0)
32
22
  arel (3.0.2)
33
- builder (3.0.0)
34
- diff-lcs (1.1.3)
35
- erubis (2.7.0)
36
- hike (1.2.1)
37
- i18n (0.6.0)
38
- journey (1.0.3)
39
- json (1.7.1)
40
- multi_json (1.3.4)
41
- rack (1.4.1)
42
- rack-cache (1.2)
43
- rack (>= 0.4)
44
- rack-ssl (1.3.2)
45
- rack
46
- rack-test (0.6.1)
47
- rack (>= 1.0)
48
- railties (3.2.3)
49
- actionpack (= 3.2.3)
50
- activesupport (= 3.2.3)
51
- rack-ssl (~> 1.3.2)
52
- rake (>= 0.8.7)
53
- rdoc (~> 3.4)
54
- thor (~> 0.14.6)
55
- rake (0.9.2.2)
56
- rdoc (3.12)
57
- json (~> 1.4)
58
- rspec (2.10.0)
59
- rspec-core (~> 2.10.0)
60
- rspec-expectations (~> 2.10.0)
61
- rspec-mocks (~> 2.10.0)
62
- rspec-core (2.10.0)
63
- rspec-expectations (2.10.0)
64
- diff-lcs (~> 1.1.3)
65
- rspec-mocks (2.10.1)
66
- rspec-rails (2.10.1)
67
- actionpack (>= 3.0)
68
- activesupport (>= 3.0)
69
- railties (>= 3.0)
70
- rspec (~> 2.10.0)
71
- sprockets (2.1.3)
72
- hike (~> 1.2)
73
- rack (~> 1.0)
74
- tilt (~> 1.1, != 1.3.0)
75
- sqlite3 (1.3.6)
23
+ builder (3.0.4)
24
+ byebug (1.6.1)
25
+ columnize (~> 0.3.6)
26
+ debugger-linecache (~> 1.2.0)
27
+ columnize (0.3.6)
28
+ debugger-linecache (1.2.0)
29
+ diff-lcs (1.2.4)
30
+ i18n (0.6.1)
31
+ multi_json (1.7.7)
32
+ rake (10.1.0)
33
+ rspec (2.14.1)
34
+ rspec-core (~> 2.14.0)
35
+ rspec-expectations (~> 2.14.0)
36
+ rspec-mocks (~> 2.14.0)
37
+ rspec-core (2.14.3)
38
+ rspec-expectations (2.14.0)
39
+ diff-lcs (>= 1.1.3, < 2.0)
40
+ rspec-mocks (2.14.1)
41
+ sqlite3 (1.3.7)
76
42
  sqlite3-ruby (1.3.3)
77
43
  sqlite3 (>= 1.3.3)
78
- thor (0.14.6)
79
- tilt (1.3.3)
80
- tzinfo (0.3.33)
44
+ tzinfo (0.3.37)
81
45
 
82
46
  PLATFORMS
83
47
  ruby
84
48
 
85
49
  DEPENDENCIES
86
50
  association_callbacks!
87
- rspec (~> 2.10.0)
88
- rspec-rails (~> 2.10.0)
89
- sqlite3-ruby
51
+ byebug (~> 1.6.0)
52
+ rake (~> 10.1.0)
53
+ rspec (~> 2.14.0)
54
+ sqlite3-ruby (~> 1.3.0)
data/README.mdown CHANGED
@@ -26,7 +26,7 @@ Here is the standard way to denormalize `last_comment_at` on posts:
26
26
  after_destroy :update_post_last_comment_at
27
27
 
28
28
  def update_post_last_comment_at
29
- post.update_attributes!(:last_comment_at => post.comments.order('created_at').last.try(:created_at))
29
+ post.update_attributes!(last_comment_at: post.comments.order('created_at').last.try(:created_at))
30
30
  end
31
31
  end
32
32
 
@@ -40,11 +40,11 @@ Here is how to do it with `association_callabacks`:
40
40
  class Post < ActiveRecord::Base
41
41
  has_many :comments
42
42
 
43
- after_create :update_last_comment_at, :source => :comments
44
- after_destroy :update_last_comment_at, :source => :comments
43
+ after_create :update_last_comment_at, source: :comments
44
+ after_destroy :update_last_comment_at, source: :comments
45
45
 
46
46
  def update_last_comment_at
47
- update_attributes!(:last_comment_at => comments.order('created_at').last.try(:created_at))
47
+ update_attributes!(last_comment_at: comments.order('created_at').last.try(:created_at))
48
48
  end
49
49
  end
50
50
 
@@ -60,7 +60,7 @@ argument, above code can be:
60
60
  after_create :update_last_comment_at
61
61
 
62
62
  def update_last_comment_at(comment)
63
- update_attributes!(:last_comment_at => comment.created_at)
63
+ update_attributes!(last_comment_at: comment.created_at)
64
64
  end
65
65
  end
66
66
 
@@ -69,7 +69,7 @@ Association callbacks can also be defined as block:
69
69
  class Post < ActiveRecord::Base
70
70
  has_many :comments
71
71
 
72
- after_destroy :source => :comments do |post|
72
+ after_destroy source: :comments do |post|
73
73
  post.decrement!(:comments_count)
74
74
  end
75
75
  end
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rspec/core/rake_task'
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
6
  desc 'Default: runs specs.'
7
- task :default => :spec
7
+ task default: :spec
8
8
 
9
9
  desc 'Run all specs in spec directory.'
10
10
  RSpec::Core::RakeTask.new(:spec)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.homepage = 'https://github.com/alexistoulotte/association_callbacks'
8
8
  s.summary = 'Callbacks for ActiveRecord associations'
9
9
  s.description = 'Provides a way to define callbacks of one ActiveRecord model into an associated one'
10
+ s.license = 'MIT'
10
11
 
11
12
  s.rubyforge_project = 'association_callbacks'
12
13
 
@@ -18,7 +19,8 @@ Gem::Specification.new do |s|
18
19
  s.add_dependency 'activerecord', '~> 3.2.0'
19
20
  s.add_dependency 'activesupport', '~> 3.2.0'
20
21
 
21
- s.add_development_dependency 'rspec', '~> 2.10.0'
22
- s.add_development_dependency 'rspec-rails', '~> 2.10.0'
23
- s.add_development_dependency 'sqlite3-ruby'
22
+ s.add_development_dependency 'byebug', '~> 1.6.0'
23
+ s.add_development_dependency 'rake', '~> 10.1.0'
24
+ s.add_development_dependency 'rspec', '~> 2.14.0'
25
+ s.add_development_dependency 'sqlite3-ruby', '~> 1.3.0'
24
26
  end
@@ -5,12 +5,8 @@ require 'active_support/concern'
5
5
 
6
6
  module AssociationCallbacks
7
7
 
8
- class << self
9
-
10
- def version
11
- @@version ||= File.read(File.expand_path(File.dirname(__FILE__) + '/../VERSION')).strip.freeze
12
- end
13
-
8
+ def self.version
9
+ @@version ||= File.read(File.expand_path(File.dirname(__FILE__) + '/../VERSION')).strip.freeze
14
10
  end
15
11
 
16
12
  end
@@ -7,28 +7,28 @@ describe AssociationCallbacks::ActiveRecord do
7
7
  it 'invokes callback defines as method' do
8
8
  post = Post.create!
9
9
  expect {
10
- Comment.create!(:post_id => post.id)
10
+ Comment.create!(post_id: post.id)
11
11
  }.to change { post.reload.comments_count }.by(1)
12
12
  end
13
13
 
14
14
  it 'invokes callback defines as method (with one argument)' do
15
15
  post = Post.create!
16
16
  expect {
17
- Comment.create!(:post => post, :created_at => 2.years.ago)
17
+ Comment.create!(post: post, created_at: 2.years.ago)
18
18
  }.to change { post.reload.last_comment_at }.from(nil)
19
19
  post.last_comment_at.to_i.should be_within(5).of(2.years.ago.to_i)
20
20
  end
21
21
 
22
22
  it 'invokes callback defines as block' do
23
23
  post = Post.create!
24
- comment = Comment.create!(:post => post)
24
+ comment = Comment.create!(post: post)
25
25
  expect {
26
26
  comment.destroy
27
27
  }.to change { post.reload.comments_count }.by(-1)
28
28
  end
29
29
 
30
30
  it 'invokes regular callbacks' do
31
- post = Post.new(:body => 'this is body', :title => 'foo')
31
+ post = Post.new(body: 'this is body', title: 'foo')
32
32
  expect {
33
33
  post.save!
34
34
  }.to change { post.texts }.from(nil).to('foo,this,is,body')
@@ -42,30 +42,30 @@ describe AssociationCallbacks::ActiveRecord do
42
42
  post = Post.create!
43
43
  comment = post.comments.create!
44
44
  expect {
45
- post.update_attributes!(:title => 'foo')
45
+ post.update_attributes!(title: 'foo')
46
46
  }.to change { comment.reload.post_updated_at }
47
47
  comment.post_updated_at.to_i.should be_within(5).of(Time.now.to_i)
48
48
  end
49
49
 
50
50
  it 'invokes callback defines as method (with one argument)' do
51
- post = Post.create!(:title => 'foo')
51
+ post = Post.create!(title: 'foo')
52
52
  comment = post.comments.create!
53
53
  expect {
54
- post.update_attributes!(:title => 'bar')
54
+ post.update_attributes!(title: 'bar')
55
55
  }.to change { comment.reload.post.title }.from('foo').to('bar')
56
56
  end
57
57
 
58
58
  it 'invokes callback defines as block' do
59
59
  post = Post.create!
60
- comment = Comment.create!(:post_id => post.id)
60
+ comment = Comment.create!(post_id: post.id)
61
61
  expect {
62
62
  post.destroy
63
63
  }.to change { comment.reload.orphan_from_id }.from(nil).to(post.id)
64
64
  end
65
65
 
66
66
  it 'invokes regular callbacks' do
67
- post = Post.create!(:title => 'foo')
68
- comment = Comment.new(:post => post)
67
+ post = Post.create!(title: 'foo')
68
+ comment = Comment.new(post: post)
69
69
  expect {
70
70
  comment.save!
71
71
  }.to change { comment.post_title }.from(nil).to('foo')
@@ -1,12 +1,12 @@
1
1
  class Comment < ActiveRecord::Base
2
2
 
3
- belongs_to :post, :inverse_of => :comments
3
+ belongs_to :post, inverse_of: :comments
4
4
 
5
- after_save :update_post_updated_at, :source => :post
5
+ after_save :update_post_updated_at, source: :post
6
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)
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
10
  end
11
11
 
12
12
  private
@@ -16,11 +16,11 @@ class Comment < ActiveRecord::Base
16
16
  end
17
17
 
18
18
  def update_post_title(post)
19
- update_attributes!(:post_title => post.title) if post.title_changed?
19
+ update_attributes!(post_title: post.title) if post.title_changed?
20
20
  end
21
21
 
22
22
  def update_post_updated_at
23
- update_attributes!(:post_updated_at => post.updated_at)
23
+ update_attributes!(post_updated_at: post.updated_at)
24
24
  end
25
25
 
26
26
  end
data/spec/mocks/post.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  class Post < ActiveRecord::Base
2
2
 
3
- has_many :comments, :inverse_of => :post
3
+ has_many :comments, inverse_of: :post
4
4
 
5
- after_create :increment_comments_count, :update_last_comment_at, :source => :comments
6
- after_destroy :source => :comments do |post|
5
+ after_create :increment_comments_count, :update_last_comment_at, source: :comments
6
+ after_destroy source: :comments do |post|
7
7
  post.decrement!(:comments_count)
8
8
  end
9
9
  before_save do |post|
@@ -17,7 +17,7 @@ class Post < ActiveRecord::Base
17
17
  end
18
18
 
19
19
  def update_last_comment_at(comment)
20
- update_attributes!(:last_comment_at => comment.created_at)
20
+ update_attributes!(last_comment_at: comment.created_at)
21
21
  end
22
22
 
23
23
  end
@@ -1,15 +1,15 @@
1
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{File.dirname(__FILE__)}/../../test.sqlite3", :timeout => 5000)
1
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{File.dirname(__FILE__)}/../../test.sqlite3", timeout: 5000)
2
2
 
3
- ActiveRecord::Base.connection.create_table(:comments, :force => true) do |t|
3
+ ActiveRecord::Base.connection.create_table(:comments, force: true) do |t|
4
4
  t.integer :orphan_from_id
5
5
  t.datetime :post_updated_at
6
6
  t.integer :post_id
7
7
  t.string :post_title
8
8
  t.timestamps
9
9
  end
10
- ActiveRecord::Base.connection.create_table(:posts, :force => true) do |t|
10
+ ActiveRecord::Base.connection.create_table(:posts, force: true) do |t|
11
11
  t.text :body
12
- t.integer :comments_count, :default => 0
12
+ t.integer :comments_count, default: 0
13
13
  t.datetime :last_comment_at
14
14
  t.text :texts
15
15
  t.string :title
metadata CHANGED
@@ -1,71 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: association_callbacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexis Toulotte
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-10 00:00:00.000000000 Z
11
+ date: 2013-07-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
- requirement: &70155409758320 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: 3.2.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70155409758320
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: activesupport
27
- requirement: &70155409757780 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ~>
31
32
  - !ruby/object:Gem::Version
32
33
  version: 3.2.0
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70155409757780
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.2.0
36
41
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70155409757300 !ruby/object:Gem::Requirement
39
- none: false
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
45
  - - ~>
42
46
  - !ruby/object:Gem::Version
43
- version: 2.10.0
47
+ version: 1.6.0
44
48
  type: :development
45
49
  prerelease: false
46
- version_requirements: *70155409757300
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.0
47
55
  - !ruby/object:Gem::Dependency
48
- name: rspec-rails
49
- requirement: &70155414636460 !ruby/object:Gem::Requirement
50
- none: false
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
54
- version: 2.10.0
61
+ version: 10.1.0
55
62
  type: :development
56
63
  prerelease: false
57
- version_requirements: *70155414636460
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 10.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.0
58
83
  - !ruby/object:Gem::Dependency
59
84
  name: sqlite3-ruby
60
- requirement: &70155414635880 !ruby/object:Gem::Requirement
61
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
62
86
  requirements:
63
- - - ! '>='
87
+ - - ~>
64
88
  - !ruby/object:Gem::Version
65
- version: '0'
89
+ version: 1.3.0
66
90
  type: :development
67
91
  prerelease: false
68
- version_requirements: *70155414635880
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.0
69
97
  description: Provides a way to define callbacks of one ActiveRecord model into an
70
98
  associated one
71
99
  email: al@alweb.org
@@ -91,34 +119,28 @@ files:
91
119
  - spec/spec_helper.rb
92
120
  - spec/support/bootsrap/database.rb
93
121
  homepage: https://github.com/alexistoulotte/association_callbacks
94
- licenses: []
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
95
125
  post_install_message:
96
126
  rdoc_options: []
97
127
  require_paths:
98
128
  - lib
99
129
  required_ruby_version: !ruby/object:Gem::Requirement
100
- none: false
101
130
  requirements:
102
- - - ! '>='
131
+ - - '>='
103
132
  - !ruby/object:Gem::Version
104
133
  version: '0'
105
- segments:
106
- - 0
107
- hash: -661193072804990363
108
134
  required_rubygems_version: !ruby/object:Gem::Requirement
109
- none: false
110
135
  requirements:
111
- - - ! '>='
136
+ - - '>='
112
137
  - !ruby/object:Gem::Version
113
138
  version: '0'
114
- segments:
115
- - 0
116
- hash: -661193072804990363
117
139
  requirements: []
118
140
  rubyforge_project: association_callbacks
119
- rubygems_version: 1.8.17
141
+ rubygems_version: 2.0.3
120
142
  signing_key:
121
- specification_version: 3
143
+ specification_version: 4
122
144
  summary: Callbacks for ActiveRecord associations
123
145
  test_files:
124
146
  - spec/association_callbacks/active_record_spec.rb