is_unique 0.0.3 → 0.0.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{is_unique}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eugene Bolshakov"]
12
- s.date = %q{2010-03-24}
12
+ s.date = %q{2010-03-26}
13
13
  s.description = %q{Makes ActiveRecord return existing records instead of creating duplicates}
14
14
  s.email = %q{eugene.bolshakov@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,6 +1,6 @@
1
1
  module IsUnique
2
2
  def self.included(base)
3
- base.extend ClassMethods
3
+ base.extend IsUnique::ClassMethods
4
4
  end
5
5
 
6
6
  module ClassMethods
@@ -16,10 +16,12 @@ module IsUnique
16
16
  'updated_at'
17
17
  ].concat(Array(options[:ignore]).map(&:to_s))
18
18
 
19
- self.class_eval do
20
- include InstanceMethods
19
+ unless self.include?(IsUnique::InstanceMethods)
20
+ self.class_eval do
21
+ include IsUnique::InstanceMethods
21
22
 
22
- before_save :calculate_unique_hash
23
+ before_save :calculate_unique_hash
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -10,6 +10,7 @@ end
10
10
  def setup_db
11
11
  ActiveRecord::Schema.define(:version => 1) do
12
12
  create_table :locations do |t|
13
+ t.string :type
13
14
  t.string :name
14
15
  t.float :lat, :lng
15
16
  t.string :alias
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class Location < ActiveRecord::Base
4
+ # String type
4
5
  # String name
5
6
  # Float lat
6
7
  # Float lng
@@ -10,6 +11,10 @@ class Location < ActiveRecord::Base
10
11
  is_unique :ignore => :alias
11
12
  end
12
13
 
14
+ class PopulatedPlace < Location
15
+ is_unique :ignore => [:name, :alias]
16
+ end
17
+
13
18
  describe "A unique model" do
14
19
  before(:each) do
15
20
  @it = Location.create(
@@ -54,4 +59,28 @@ describe "A unique model" do
54
59
  should change(Location, :count).by(1)
55
60
  new_record.should_not == @it
56
61
  end
62
+
63
+ context "that is a subclass of another model" do
64
+ before(:each) do
65
+ @it = PopulatedPlace.create(
66
+ :name => 'London',
67
+ :lat => '51.5084152563931',
68
+ :lng => '-0.125532746315002',
69
+ :alias => 'Londinium'
70
+ )
71
+ end
72
+
73
+ it "should be able to override columns that should be ignored" do
74
+ new_record = @it.clone
75
+ new_record.name = 'Greater London'
76
+ new_record.alias = 'London, UK'
77
+ lambda { new_record.save! }.
78
+ should_not change(PopulatedPlace, :count)
79
+ end
80
+
81
+ it "should run callbacks just once" do
82
+ @it.should_receive(:calculate_unique_hash).once
83
+ @it.save
84
+ end
85
+ end
57
86
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eugene Bolshakov
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-24 00:00:00 +03:00
17
+ date: 2010-03-26 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency