touch 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +11 -0
- data/README.md +10 -0
- data/Rakefile +9 -0
- data/lib/touch.rb +1 -0
- data/lib/touch/version.rb +1 -1
- data/{spec → test}/support/models.rb +4 -2
- data/test/test_helper.rb +16 -0
- data/test/touch/create_test.rb +22 -0
- data/test/touch/destroy_test.rb +22 -0
- data/test/touch/update_test.rb +22 -0
- data/touch.gemspec +2 -1
- metadata +44 -27
- data/.rspec +0 -2
- data/Gemfile.lock +0 -73
- data/spec/spec_helper.rb +0 -18
- data/spec/touch_spec.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7439aac65a0d5479bc1f8fab6f05c2a378d0a6
|
4
|
+
data.tar.gz: 34cdf5d5b369ee9c42dac977822d88ff24e8bef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2811601e64be85cddf38202c2454f67343acc6de03dc457c589f70883fd0254bb4946d2a1a096de4046c0ba9ec7bce1e9535d59e5494714c769ffbd9c29628b
|
7
|
+
data.tar.gz: e73660aa7765002e40d60dbae355ae9168986caf59233cb0dbb820c715df1f060c614f78ba334b23f8b855a37bbc5622b47170ca5ceca904f5c78c992ba26b99
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
notifications:
|
5
|
+
email: false
|
6
|
+
rvm:
|
7
|
+
- 2.3.0
|
8
|
+
- '2.2'
|
9
|
+
env:
|
10
|
+
global:
|
11
|
+
secure: Y6h1xkzJFjwnm0Dzn0EpNKIKyXdzyGPws4rXq7Z/VGnu0tjwBpW9/aM2ecgNjknU/8EAan4fMOG2EZPr2qzbjOR/ZVijdhsIAA0PCTlVSdTqEnthUvaJHJg8DeTcfAN0Rj/XJ/EiTXrYJWIFUYGUsrnku/0MRoSxRYL8Kp8Q+fY=
|
data/README.md
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
# Touch
|
2
2
|
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/touch.png)](https://travis-ci.org/fnando/touch)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/fnando/touch/badges/gpa.svg)](https://codeclimate.com/github/fnando/touch)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/touch/badges/coverage.svg)](https://codeclimate.com/github/fnando/touch/coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/touch.svg)](https://rubygems.org/gems/touch)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/touch.svg)](https://rubygems.org/gems/touch)
|
8
|
+
|
3
9
|
Touch a parent's collection on ActiveRecord.
|
4
10
|
|
11
|
+
## Why not just using `belongs_to :assoc, touch: true`?
|
12
|
+
|
13
|
+
Well, you'll have a fine control for each association, since `touch: true` updates the `updated_at` magic field.
|
14
|
+
|
5
15
|
## Installation
|
6
16
|
|
7
17
|
Add this line to your application's Gemfile:
|
data/Rakefile
CHANGED
data/lib/touch.rb
CHANGED
data/lib/touch/version.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
ActiveRecord::Migration.verbose = false
|
2
|
+
|
1
3
|
ActiveRecord::Schema.define(:version => 0) do
|
2
4
|
create_table :users do |t|
|
3
5
|
t.datetime :tasks_updated_at
|
4
|
-
t.timestamps
|
6
|
+
t.timestamps null: false
|
5
7
|
end
|
6
8
|
|
7
9
|
create_table :tasks do |t|
|
8
10
|
t.string :title
|
9
11
|
t.belongs_to :user
|
10
|
-
t.timestamps
|
12
|
+
t.timestamps null: false
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
Bundler.require
|
6
|
+
|
7
|
+
require "minitest/utils"
|
8
|
+
require "minitest/autorun"
|
9
|
+
require "touch"
|
10
|
+
|
11
|
+
ActiveRecord::Base.establish_connection(
|
12
|
+
adapter: "sqlite3",
|
13
|
+
database: ":memory:"
|
14
|
+
)
|
15
|
+
|
16
|
+
require_relative "support/models"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class CreateTest < Minitest::Test
|
4
|
+
let(:user) { User.create! }
|
5
|
+
let(:task) { user.tasks.create! }
|
6
|
+
|
7
|
+
test "updates the parent's collection field" do
|
8
|
+
Task.touch(:user)
|
9
|
+
tasks_updated_at = user.tasks_updated_at
|
10
|
+
user.tasks.create!
|
11
|
+
|
12
|
+
refute_equal tasks_updated_at, user.reload.tasks_updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
test "updates the parent record" do
|
16
|
+
Task.touch(:user)
|
17
|
+
updated_at = user.updated_at
|
18
|
+
user.tasks.create!
|
19
|
+
|
20
|
+
refute_equal updated_at, user.reload.updated_at
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class DestroyTest < Minitest::Test
|
4
|
+
let(:user) { User.create! }
|
5
|
+
let(:task) { user.tasks.create! }
|
6
|
+
|
7
|
+
test "updates the parent's collection field" do
|
8
|
+
Task.touch(:user)
|
9
|
+
tasks_updated_at = user.reload.tasks_updated_at
|
10
|
+
task.destroy!
|
11
|
+
|
12
|
+
refute_equal tasks_updated_at, user.reload.tasks_updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
test "updates the parent record" do
|
16
|
+
Task.touch(:user)
|
17
|
+
updated_at = user.reload.updated_at
|
18
|
+
task.destroy!
|
19
|
+
|
20
|
+
refute_equal updated_at, user.reload.updated_at
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class UpdateTest < Minitest::Test
|
4
|
+
let(:user) { User.create! }
|
5
|
+
let(:task) { user.tasks.create! }
|
6
|
+
|
7
|
+
test "updates the parent's collection field" do
|
8
|
+
Task.touch(:user)
|
9
|
+
tasks_updated_at = user.reload.tasks_updated_at
|
10
|
+
task.update_attributes title: "Some title"
|
11
|
+
|
12
|
+
refute_equal tasks_updated_at, user.reload.tasks_updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
test "updates the parent record" do
|
16
|
+
Task.touch(:user)
|
17
|
+
updated_at = user.updated_at
|
18
|
+
task.update_attributes title: "Some title"
|
19
|
+
|
20
|
+
refute_equal updated_at, user.reload.updated_at
|
21
|
+
end
|
22
|
+
end
|
data/touch.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.add_dependency "activerecord"
|
19
19
|
spec.add_development_dependency "bundler"
|
20
20
|
spec.add_development_dependency "rake"
|
21
|
-
spec.add_development_dependency "
|
21
|
+
spec.add_development_dependency "minitest-utils"
|
22
22
|
spec.add_development_dependency "pry-meta"
|
23
23
|
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
24
25
|
end
|
metadata
CHANGED
@@ -1,97 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: touch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: minitest-utils
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry-meta
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
111
|
description: Touch a parent's collection on ActiveRecord.
|
@@ -101,18 +115,19 @@ executables: []
|
|
101
115
|
extensions: []
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
|
-
- .gitignore
|
105
|
-
- .
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
106
120
|
- Gemfile
|
107
|
-
- Gemfile.lock
|
108
121
|
- LICENSE.txt
|
109
122
|
- README.md
|
110
123
|
- Rakefile
|
111
124
|
- lib/touch.rb
|
112
125
|
- lib/touch/version.rb
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
126
|
+
- test/support/models.rb
|
127
|
+
- test/test_helper.rb
|
128
|
+
- test/touch/create_test.rb
|
129
|
+
- test/touch/destroy_test.rb
|
130
|
+
- test/touch/update_test.rb
|
116
131
|
- touch.gemspec
|
117
132
|
homepage: http://github.com/fnando/touch
|
118
133
|
licenses:
|
@@ -124,21 +139,23 @@ require_paths:
|
|
124
139
|
- lib
|
125
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
126
141
|
requirements:
|
127
|
-
- -
|
142
|
+
- - ">="
|
128
143
|
- !ruby/object:Gem::Version
|
129
144
|
version: '0'
|
130
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
146
|
requirements:
|
132
|
-
- -
|
147
|
+
- - ">="
|
133
148
|
- !ruby/object:Gem::Version
|
134
149
|
version: '0'
|
135
150
|
requirements: []
|
136
151
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.5.1
|
138
153
|
signing_key:
|
139
154
|
specification_version: 4
|
140
155
|
summary: Touch a parent's collection on ActiveRecord.
|
141
156
|
test_files:
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
157
|
+
- test/support/models.rb
|
158
|
+
- test/test_helper.rb
|
159
|
+
- test/touch/create_test.rb
|
160
|
+
- test/touch/destroy_test.rb
|
161
|
+
- test/touch/update_test.rb
|
data/.rspec
DELETED
data/Gemfile.lock
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
touch (0.0.1)
|
5
|
-
activerecord
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activemodel (4.0.0)
|
11
|
-
activesupport (= 4.0.0)
|
12
|
-
builder (~> 3.1.0)
|
13
|
-
activerecord (4.0.0)
|
14
|
-
activemodel (= 4.0.0)
|
15
|
-
activerecord-deprecated_finders (~> 1.0.2)
|
16
|
-
activesupport (= 4.0.0)
|
17
|
-
arel (~> 4.0.0)
|
18
|
-
activerecord-deprecated_finders (1.0.3)
|
19
|
-
activesupport (4.0.0)
|
20
|
-
i18n (~> 0.6, >= 0.6.4)
|
21
|
-
minitest (~> 4.2)
|
22
|
-
multi_json (~> 1.3)
|
23
|
-
thread_safe (~> 0.1)
|
24
|
-
tzinfo (~> 0.3.37)
|
25
|
-
arel (4.0.0)
|
26
|
-
atomic (1.1.10)
|
27
|
-
awesome_print (1.1.0)
|
28
|
-
builder (3.1.4)
|
29
|
-
coderay (1.0.9)
|
30
|
-
diff-lcs (1.2.4)
|
31
|
-
i18n (0.6.4)
|
32
|
-
method_source (0.8.1)
|
33
|
-
minitest (4.7.5)
|
34
|
-
multi_json (1.7.7)
|
35
|
-
pry (0.9.12.2)
|
36
|
-
coderay (~> 1.0.5)
|
37
|
-
method_source (~> 0.8)
|
38
|
-
slop (~> 3.4)
|
39
|
-
pry-meta (0.0.5)
|
40
|
-
awesome_print
|
41
|
-
pry
|
42
|
-
pry-nav
|
43
|
-
pry-remote
|
44
|
-
pry-nav (0.2.3)
|
45
|
-
pry (~> 0.9.10)
|
46
|
-
pry-remote (0.1.7)
|
47
|
-
pry (~> 0.9)
|
48
|
-
slop (~> 3.0)
|
49
|
-
rake (10.1.0)
|
50
|
-
rspec (2.14.1)
|
51
|
-
rspec-core (~> 2.14.0)
|
52
|
-
rspec-expectations (~> 2.14.0)
|
53
|
-
rspec-mocks (~> 2.14.0)
|
54
|
-
rspec-core (2.14.4)
|
55
|
-
rspec-expectations (2.14.0)
|
56
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
57
|
-
rspec-mocks (2.14.1)
|
58
|
-
slop (3.4.5)
|
59
|
-
sqlite3 (1.3.7)
|
60
|
-
thread_safe (0.1.0)
|
61
|
-
atomic
|
62
|
-
tzinfo (0.3.37)
|
63
|
-
|
64
|
-
PLATFORMS
|
65
|
-
ruby
|
66
|
-
|
67
|
-
DEPENDENCIES
|
68
|
-
bundler
|
69
|
-
pry-meta
|
70
|
-
rake
|
71
|
-
rspec
|
72
|
-
sqlite3
|
73
|
-
touch!
|
data/spec/spec_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
Bundler.require
|
3
|
-
|
4
|
-
require "touch"
|
5
|
-
|
6
|
-
ActiveRecord::Base.establish_connection(
|
7
|
-
adapter: "sqlite3",
|
8
|
-
database: ":memory:"
|
9
|
-
)
|
10
|
-
|
11
|
-
require "support/models"
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
-
config.run_all_when_everything_filtered = true
|
16
|
-
config.filter_run :focus
|
17
|
-
config.order = "random"
|
18
|
-
end
|
data/spec/touch_spec.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Touch do
|
4
|
-
let(:user) { User.create! }
|
5
|
-
let(:task) { user.tasks.create! }
|
6
|
-
|
7
|
-
context "on create" do
|
8
|
-
it "updates the parent's collection field" do
|
9
|
-
Task.touch(:user)
|
10
|
-
|
11
|
-
expect {
|
12
|
-
user.tasks.create!
|
13
|
-
}.to change { user.reload.tasks_updated_at }
|
14
|
-
end
|
15
|
-
|
16
|
-
it "updates the parent record" do
|
17
|
-
Task.touch(:user)
|
18
|
-
|
19
|
-
expect {
|
20
|
-
user.tasks.create!
|
21
|
-
}.to change { user.reload.updated_at }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "on update" do
|
26
|
-
it "updates the parent's collection field" do
|
27
|
-
Task.touch(:user)
|
28
|
-
|
29
|
-
expect {
|
30
|
-
task.update_attributes title: "Some title"
|
31
|
-
}.to change { user.reload.tasks_updated_at }
|
32
|
-
end
|
33
|
-
|
34
|
-
it "updates the parent record" do
|
35
|
-
Task.touch(:user)
|
36
|
-
|
37
|
-
expect {
|
38
|
-
task.update_attributes title: "Some title"
|
39
|
-
}.to change { user.reload.updated_at }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context "on destroy" do
|
44
|
-
it "updates the parent's collection field" do
|
45
|
-
Task.touch(:user)
|
46
|
-
|
47
|
-
expect {
|
48
|
-
task.destroy!
|
49
|
-
}.to change { user.reload.tasks_updated_at }
|
50
|
-
end
|
51
|
-
|
52
|
-
it "updates the parent record" do
|
53
|
-
Task.touch(:user)
|
54
|
-
|
55
|
-
expect {
|
56
|
-
task.destroy!
|
57
|
-
}.to change { user.reload.updated_at }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|