Skip to content

Commit

Permalink
Building a hash with _attrs now works in combination with inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ginty committed Oct 22, 2011
1 parent cd2d2ad commit d92e3aa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Overview of Changes

## 0.3.1

* Bugfix, generating a hash of attributes via _attrs did not work with factory methods
that used the inherit method

## 0.3.0

* Updated README to present the crank syntax as the default
Expand Down
10 changes: 6 additions & 4 deletions lib/cranky/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def n
@n += 1
end

def inherit(what, overrides={})
build(what, overrides.merge(options))
end

# Execute the requested factory method, crank out the target object!
def crank_it(what, overrides)
if what.to_s =~ /(.*)_attrs$/
Expand All @@ -86,6 +82,12 @@ def define(defaults={})
current_job.execute
end

def inherit(what, overrides={})
overrides = overrides.merge(options)
overrides = overrides.merge(:_return_attributes => true) if current_job.return_attributes
build(what, overrides)
end

def current_job
@pipeline.last
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cranky/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Cranky
class Job

attr_writer :defaults
attr_reader :overrides
attr_reader :overrides, :return_attributes

def initialize(target, overrides={})
@defaults = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/cranky/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Cranky
VERSION = "0.3.0"
VERSION = "0.3.1"
end
8 changes: 7 additions & 1 deletion rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ task :release_tag do
system "git tag -a v#{Cranky::VERSION} -m 'version #{Cranky::VERSION}'"
end

# Push to github
desc "Push to Github"
task :push do
system "git push --tags origin master"
end

desc "Build the gem"
task :build do
system "bundle exec gem build cranky.gemspec"
end

desc "Release version #{Cranky::VERSION}"
task :release => [:build, :release_tag] do
task :release => [:build, :release_tag, :push] do
system "bundle exec gem push cranky-#{Cranky::VERSION}.gem"
end

Expand Down
4 changes: 4 additions & 0 deletions spec/cranky_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,9 @@
crank(:user_attrs).size.should == 6
end

specify "attributes for works with factory methods using inherit" do
crank(:admin_by_define_attrs).class.should == Hash
end

end

0 comments on commit d92e3aa

Please sign in to comment.