polymorpheus 0.1 → 0.2

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.
@@ -54,8 +54,13 @@ module Polymorpheus
54
54
  # Getter method
55
55
  define_method polymorphic_api do
56
56
  if key = self.send("#{polymorphic_api}_active_key")
57
+ # we are connecting to an existing item in the db
57
58
  self.send key.gsub(/_id$/,'')
58
- end
59
+ else
60
+ # we can also link to a new record if we're careful
61
+ objs = associations.map { |association| self.send(association) }.compact
62
+ objs.first if objs.length == 1
63
+ end
59
64
  end
60
65
 
61
66
  # Setter method
@@ -1,3 +1,3 @@
1
1
  module Polymorpheus
2
- VERSION = '0.1'
2
+ VERSION = '0.2'
3
3
  end
@@ -70,6 +70,13 @@ describe Shoe do
70
70
  let(:attributes) { { man: man } }
71
71
  it_should_behave_like "valid polymorphic relationship"
72
72
  end
73
+ context "and the record we are linking to is a new record" do
74
+ let(:new_man) { Man.new }
75
+ let(:attributes) { { man: new_man } }
76
+ specify { shoe.wearer.should == new_man }
77
+ specify { shoe.wearer_active_key.should be_nil }
78
+ specify { shoe.wearer_query_condition.should be_nil }
79
+ end
73
80
  end
74
81
 
75
82
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymorpheus
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-13 00:00:00.000000000Z
12
+ date: 2011-12-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: foreigner
16
- requirement: &70170816060540 !ruby/object:Gem::Requirement
16
+ requirement: &70363112837300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70170816060540
24
+ version_requirements: *70363112837300
25
25
  description: Provides a database-friendly method for polymorphic relationships
26
26
  email: bsingh@wegowise.com
27
27
  executables: []