paranoid2 1.1.3 → 1.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: 5f9a15a900223d0201ed3b29ca9c35ac48800545
4
- data.tar.gz: 4214d3d5cbceb9dfc2f66f035f4a794b96208ec2
3
+ metadata.gz: 41f8a90b29f702033ddfbcd98b0a63efa4f92a9e
4
+ data.tar.gz: 8e4db488f8d9fa3b829be3f3408c8eebc8999ca9
5
5
  SHA512:
6
- metadata.gz: ba9e499c0ddb509a80e6f28c99cd99e2eb20abfed81c39d83c4f36943925ff129221e135a74c885002e1a11a85f837d122cecdae47d29c52e9e75e569495dc98
7
- data.tar.gz: 5c0d65b7cb3bd6b718b6094bdd9f784e91f04d1901a8d320cdf99dbf2147a835d84b24ff639af8eee3b413ec64beaacb1286749a5ef911d56152ac3cb614f980
6
+ metadata.gz: 85c9bef842a3c280a85ad375ef80e8586ef87397092dc8b15a32a3bac7fbf66af4445583d28b743b3ae88423e033eee9ce21c7b7ad64482c7ea55c24ae2ef0cc
7
+ data.tar.gz: b0533d5734434f3d0d21bc07c7789326b201dbfc55748198209899040e491122d7858745c553f9efbe8fe4a23dea488e2abae725ab36e88eea1cd9b0a31e450f
@@ -19,6 +19,6 @@ module Paranoid2
19
19
  def with_deleted
20
20
  all.tap { |s| s.default_scoped = false }
21
21
  end
22
- end
22
+ end
23
23
  end
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module Paranoid2
2
- VERSION = '1.1.3'
2
+ VERSION = '1.1.4'
3
3
  end
data/paranoid2.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency 'activerecord', '>= 4.0.0.rc1'
21
+ gem.add_dependency 'activerecord', '>= 4.0.0'
22
22
 
23
23
  gem.add_development_dependency "rake"
24
24
  gem.add_development_dependency "sqlite3"
@@ -117,12 +117,24 @@ describe Paranoid2 do
117
117
  b.destroy
118
118
  parent1.paranoid_models.count.must_equal 0
119
119
  parent1.paranoid_models.only_deleted.count.must_equal 1
120
-
120
+
121
121
  c = model.create(parent_model: parent1)
122
122
  parent1.paranoid_models.with_deleted.count.must_equal 2
123
123
  parent1.paranoid_models.with_deleted.must_equal [a, c]
124
124
  end
125
125
 
126
+ it 'allows "Model#includes"' do
127
+ parent1 = ParentModel.create
128
+ parent2 = ParentModel.create
129
+ a = model.create(parent_model: parent1)
130
+ b = model.create(parent_model: parent2)
131
+
132
+ l = ActiveRecord::Base.logger
133
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
134
+ res = model.includes(:parent_model).merge(ParentModel.with_deleted).references(:parent_model).to_a
135
+ ActiveRecord::Base.logger = l
136
+ end
137
+
126
138
  it 'works with has_many_through relationships' do
127
139
  employer = Employer.create
128
140
  employee = Employee.create
@@ -170,7 +182,7 @@ describe Paranoid2 do
170
182
  a.reload
171
183
 
172
184
  parent.wont_be :destroyed?
173
- a.wont_be :destroyed?
185
+ a.wont_be :destroyed?
174
186
  end
175
187
 
176
188
  it 'restores belongs_to associations' do
@@ -197,7 +209,7 @@ describe Paranoid2 do
197
209
  it 'delete without callback' do
198
210
  object.save
199
211
  object.delete
200
-
212
+
201
213
  object.callback_called.must_be_nil
202
214
  end
203
215
 
@@ -218,5 +230,13 @@ describe Paranoid2 do
218
230
  scope = model.where(name: 'foo').only_deleted
219
231
  scope.where_values_hash['name'].must_equal 'foo'
220
232
  end
233
+
234
+ it 'validates uniqueness with scope' do
235
+ a = model.create!(name: 'yury', phone: '9106701550')
236
+ b = model.create(name: 'bla', phone: '9106701550')
237
+ b.wont_be :valid?
238
+ a.destroy
239
+ b.must_be :valid?
240
+ end
221
241
  end
222
242
  end
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ ActiveRecord::Base.establish_connection adapter: 'sqlite3', :database => DB_FILE
12
12
 
13
13
  [ 'CREATE TABLE parent_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)',
14
14
  'CREATE TABLE paranoid_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER, deleted_at DATETIME)',
15
- 'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32))',
15
+ 'CREATE TABLE featureful_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME, name VARCHAR(32), phone VARCHAR(20))',
16
16
  'CREATE TABLE plain_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)',
17
17
  'CREATE TABLE callback_models (id INTEGER NOT NULL PRIMARY KEY, deleted_at DATETIME)',
18
18
  'CREATE TABLE related_models (id INTEGER NOT NULL PRIMARY KEY, parent_model_id INTEGER NOT NULL, deleted_at DATETIME)',
data/spec/spec_models.rb CHANGED
@@ -15,6 +15,9 @@ class FeaturefulModel < ActiveRecord::Base
15
15
  paranoid
16
16
 
17
17
  validates :name, presence: true, uniqueness: true
18
+ validates :phone, uniqueness: {conditions: -> { paranoid_scope } }
19
+
20
+ scope :find_last, lambda {|name| where(name: name).last }
18
21
  end
19
22
 
20
23
  class CallbackModel < ActiveRecord::Base
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paranoid2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-23 00:00:00.000000000 Z
11
+ date: 2014-02-19 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
- version: 4.0.0.rc1
19
+ version: 4.0.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
- version: 4.0.0.rc1
26
+ version: 4.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
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: sqlite3
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
  description: paranoid models for rails 4
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -82,17 +82,17 @@ require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - '>='
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.0.3
95
+ rubygems_version: 2.2.0
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: paranoid models for rails 4