polymorphic_integer_type 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWZhZjhkYzJiNTgxNTBlZTUwYzYwOTY3YjE0MThlNzAyYWUxNTJlZA==
4
+ Y2I3YWE0OWMwZDNkZWM0MzkyZjY0NGQyNTJmMGUyZjdmY2UxYzIzNQ==
5
5
  data.tar.gz: !binary |-
6
- M2JjYWIxZDU3Nzc3NjViMjI2MDc3ZTllNWRiMGNkZjEzNmUyNjQ0Zg==
6
+ OTFkNWRmNjhiMTkwNWJmZGVhMjFkZmJiZWU5ZDQzZTRmY2ZhZGRlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODU0ZmI0NjhiYzM5NTcwYWM3NjU0YzIyYjg0ODJlMGMyOWMxNWYwNWMyZGMz
10
- NWNjMzBhNjhjYzhiMmU1ZGU0YTUxNjhhZjU5ZDliNTQ5ZDZhYTgzMjg2MjU3
11
- MzVmNzEwNTc5Y2IzYjI0YTE0NTM4NjYxYTY2MDk1M2RjMDI5NmE=
9
+ NGVkMWNlN2Y5MmRlNzNlMmM2NTkwMTEzNTcyNGNmYTMzOTdlYmRlYjU1YTAy
10
+ MDQyOWI4YTEyNmQ4MzIzNDFhMGIzZjAxMTNkMGI1MzMzY2ZkZDUzMzNhODg5
11
+ NmE0MTBkYWJkOGE5NTdmODEwY2YwMGFjMjkwY2JiNWNhZDk4MGI=
12
12
  data.tar.gz: !binary |-
13
- NTE0NWY2MWJmNWRiMTE0MzdlZDcyOTcwOGI0ZGFlN2I3OTZjNmJkOTZlNWY2
14
- MDE0NjYwMmViMzVhM2M1MmJkYWU1N2UxYzZkNmEzZWM0MGJiNjMzNmZmYTAz
15
- MzQ5ODFiZmFjNTM1ZGVlYTRkYmIyYmEwYjAwZDA2MGZiMmNmNjA=
13
+ YzM1NDAzOTg5YjY5MjQyNGQ0MGU2ZDFhZDZjYWEyMmNjMjhjZTEyZGM4OTgw
14
+ N2NiZTk5Y2ZmODE0N2NjOGU2ZWJkY2JkMGRmMzc5ZWRhNzc0MjBhMTgzMjQy
15
+ Y2NlMzY5NDEzZGM0ZGNkNGYwYWQ4Y2U3Y2NlZTk1ZGQ3OTM1MjI=
@@ -17,6 +17,7 @@ module PolymorphicIntegerType
17
17
  end
18
18
 
19
19
  define_method "#{foreign_type}=" do |klass|
20
+ klass = klass.base_class if klass.kind_of?(Class)
20
21
  enum = mapping.key(klass.to_s) || klass
21
22
  super(enum)
22
23
  end
@@ -1,3 +1,3 @@
1
1
  module PolymorphicIntegerType
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -131,5 +131,15 @@ describe PolymorphicIntegerType do
131
131
 
132
132
  end
133
133
 
134
+ context "when the association is an STI table" do
135
+ let(:link) { Link.create(:source => source, :target => whiskey) }
136
+ let(:source) { Dog.create(:name => "Bela", :kind => "Dog", :owner => owner) }
137
+ it "should have the proper id, type and object for the source" do
138
+ expect(link.source_id).to eql source.id
139
+ expect(link.source_type).to eql "Animal"
140
+ expect(link.source).to eql source
141
+ end
142
+ end
143
+
134
144
 
135
145
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'polymorphic_integer_type'
3
3
  require 'support/configuration'
4
4
  require 'support/link'
5
5
  require 'support/animal'
6
+ require 'support/dog'
6
7
  require 'support/person'
7
8
  require 'support/food'
8
9
  require 'support/drink'
@@ -0,0 +1,4 @@
1
+ class Dog < Animal
2
+
3
+
4
+ end
@@ -3,6 +3,7 @@ class CreateAnimalTable < ActiveRecord::Migration
3
3
  def up
4
4
  create_table :animals do |t|
5
5
  t.string :name
6
+ t.string :type
6
7
  t.string :kind
7
8
  t.integer :owner_id
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymorphic_integer_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle d'Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,6 +116,7 @@ files:
116
116
  - spec/support/active_record.rb
117
117
  - spec/support/animal.rb
118
118
  - spec/support/configuration.rb
119
+ - spec/support/dog.rb
119
120
  - spec/support/drink.rb
120
121
  - spec/support/food.rb
121
122
  - spec/support/link.rb
@@ -145,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  version: '0'
146
147
  requirements: []
147
148
  rubyforge_project:
148
- rubygems_version: 2.1.11
149
+ rubygems_version: 2.2.2
149
150
  signing_key:
150
151
  specification_version: 4
151
152
  summary: Use integers rather than strings for the _type field
@@ -155,6 +156,7 @@ test_files:
155
156
  - spec/support/active_record.rb
156
157
  - spec/support/animal.rb
157
158
  - spec/support/configuration.rb
159
+ - spec/support/dog.rb
158
160
  - spec/support/drink.rb
159
161
  - spec/support/food.rb
160
162
  - spec/support/link.rb