bsns 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/bsns.rb +3 -1
  2. data/spec/bsns_spec.rb +21 -0
  3. metadata +1 -1
data/lib/bsns.rb CHANGED
@@ -26,8 +26,10 @@ module BSNS
26
26
  if opts[:embedded]
27
27
  obj = klass.new data
28
28
  else
29
- if data.type_of? Hash
29
+ if data.is_a? Hash
30
30
  obj = klass.load data[0]
31
+ else
32
+ obj = klass.load data
31
33
  end
32
34
  end
33
35
  end
data/spec/bsns_spec.rb CHANGED
@@ -11,6 +11,8 @@ class Buzzle < BSNS::Base
11
11
  has_many :fizzles, :as => :enemies, :with => :reason
12
12
  has_many :fizzles, :as => :opinions, :with => :opinion
13
13
  has_one :cat, :embedded => true
14
+ has_many :fizzles, :as => :embedded_fizzles, :embedded => true
15
+ has_one :wizzle, :embedded => :true
14
16
 
15
17
  end
16
18
 
@@ -20,6 +22,8 @@ class Wizzle < BSNS::Base
20
22
 
21
23
  acts_as_collection
22
24
 
25
+ has_one :fizzle
26
+
23
27
  end
24
28
 
25
29
  class Fizzle < BSNS::Base
@@ -138,4 +142,21 @@ describe BSNS do
138
142
  fuzz.cats[0].thing.should == 'bad breath'
139
143
  end
140
144
 
145
+ it "should handle associations of embedded associations" do
146
+ buzz = Buzzle.load 'buzz'
147
+ buzz.embedded_fizzles.length.should == 1
148
+ buzz.embedded_fizzles[0].name.should == "Embedded Fizzle"
149
+ cats = buzz.embedded_fizzles[0].cats
150
+ cats.length.should == 2
151
+ cats[0].thing.should == 'poops a lot'
152
+ cats[1].thing.should == 'sharp claws'
153
+ end
154
+
155
+ it "should handle embedded associations for has_one links" do
156
+ buzz = Buzzle.load 'buzz'
157
+ fizzle = buzz.wizzle.fizzle
158
+ fizzle.name.should == "Fuzzy Wuzzy"
159
+ fizzle.cats.length.should == 1
160
+ end
161
+
141
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: