Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/dm-sweatshop/sweatshop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ def self.attributes(klass, name)
proc = model_map[klass][name.to_sym].pick

if proc
expand_callable_values(proc.call)
hash = proc.call
super_attributes = {}
if hash.key?(:super)
super_attributes = attributes(klass.superclass, hash.delete(:super) || name)
end
super_attributes.merge(expand_callable_values(hash))
elsif klass.superclass.is_a?(DataMapper::Model)
attributes(klass.superclass, name)
else
Expand Down
18 changes: 18 additions & 0 deletions spec/dm-sweatshop/model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Widget
class Wonket < Widget
property :size, String
end

class ExtendedWidget < Widget
end

class Order
include DataMapper::Resource
Expand Down Expand Up @@ -87,6 +90,21 @@ class Order

Order.gen.widgets.should_not be_empty
end

it "should allow super with STI fixtures" do
Widget.fix {{
:name => "red"
}}

ExtendedWidget.fix {{
:super => nil,
:price => 50
}}

w = ExtendedWidget.gen
w.name.should == "red"
w.price.should == 50
end
end

describe ".make" do
Expand Down