composite_primary_keys 2.2.0 → 2.2.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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ == 2.2.1 2009-01-21
2
+
3
+ * fix ActiveRecord#exists? to work when passing conditions instead of ids
4
+
1
5
  == 2.2.0 2008-10-29
2
6
 
3
7
  * Rails 2.2.0 compatibility
data/Manifest.txt CHANGED
@@ -100,6 +100,7 @@ test/test_composite_arrays.rb
100
100
  test/test_create.rb
101
101
  test/test_delete.rb
102
102
  test/test_dummy.rb
103
+ test/test_exists.rb
103
104
  test/test_find.rb
104
105
  test/test_ids.rb
105
106
  test/test_miscellaneous.rb
@@ -183,8 +183,12 @@ module CompositePrimaryKeys
183
183
  # Example:
184
184
  # Person.exists?(5,7)
185
185
  def exists?(ids)
186
- obj = find(ids) rescue false
187
- !obj.nil? and obj.is_a?(self)
186
+ if ids.is_a?(Array) && ids.first.is_a?(String)
187
+ count(:conditions => ids).size > 0
188
+ else
189
+ obj = find(ids) rescue false
190
+ !obj.nil? and obj.is_a?(self)
191
+ end
188
192
  end
189
193
 
190
194
  # Deletes the record with the given +ids+ without instantiating an object first, e.g. delete(1,2)
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 2
5
- TINY = 0
5
+ TINY = 1
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -0,0 +1,27 @@
1
+ require 'abstract_unit'
2
+ require 'fixtures/article'
3
+ require 'fixtures/department'
4
+
5
+ class TestExists < Test::Unit::TestCase
6
+ fixtures :articles, :departments
7
+
8
+ def test_single_key_exists_giving_id
9
+ assert Article.exists?(1)
10
+ end
11
+
12
+ def test_single_key_exists_giving_condition
13
+ assert Article.exists?(['name = ?', 'Article One'])
14
+ end
15
+
16
+ def test_composite_key_exists_giving_ids_as_string
17
+ assert Department.exists?('1,1,')
18
+ end
19
+
20
+ def test_composite_key_exists_giving_ids_as_array
21
+ assert Department.exists?([1,1])
22
+ end
23
+
24
+ def test_composite_key_exists_giving_ids_as_condition
25
+ assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
26
+ end
27
+ end
data/tmp/test.db CHANGED
Binary file
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Composite Primary Keys</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/compositekeys"; return false'>
35
35
  Get Version
36
- <a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.0</a>
36
+ <a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.1</a>
37
37
  </div>
38
38
  <h1>&#8594; Ruby on Rails</h1>
39
39
  <h1>&#8594; ActiveRecords</h1>
@@ -183,7 +183,7 @@ other stories and things.</p>
183
183
  <h2>Contact</h2>
184
184
  <p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
185
185
  <p class="coda">
186
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 29th October 2008<br>
186
+ <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 21st January 2009<br>
187
187
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
188
188
  </p>
189
189
  </div>
@@ -1,3 +1,3 @@
1
1
  // Announcement JS file
2
- var version = "2.2.0";
2
+ var version = "2.2.1";
3
3
  MagicAnnouncement.show('compositekeys', version);
data/website/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Version JS file
2
- var version = "2.2.0";
2
+ var version = "2.2.1";
3
3
 
4
4
  document.write(" - " + version);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-29 00:00:00 -05:00
12
+ date: 2009-01-21 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.2
33
+ version: 1.8.3
34
34
  version:
35
35
  description: Composite key support for ActiveRecords
36
36
  email: drnicwilliams@gmail.com
@@ -150,6 +150,7 @@ files:
150
150
  - test/test_create.rb
151
151
  - test/test_delete.rb
152
152
  - test/test_dummy.rb
153
+ - test/test_exists.rb
153
154
  - test/test_find.rb
154
155
  - test/test_ids.rb
155
156
  - test/test_miscellaneous.rb
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  requirements: []
193
194
 
194
195
  rubyforge_project: compositekeys
195
- rubygems_version: 1.3.0
196
+ rubygems_version: 1.3.1
196
197
  signing_key:
197
198
  specification_version: 2
198
199
  summary: Composite key support for ActiveRecords
@@ -205,6 +206,7 @@ test_files:
205
206
  - test/test_create.rb
206
207
  - test/test_delete.rb
207
208
  - test/test_dummy.rb
209
+ - test/test_exists.rb
208
210
  - test/test_find.rb
209
211
  - test/test_ids.rb
210
212
  - test/test_miscellaneous.rb