Skip to content

Commit

Permalink
specs in app are saying context and options from save; with defaultin…
Browse files Browse the repository at this point in the history
…g new to the bound model
  • Loading branch information
hookercookerman committed Feb 1, 2013
1 parent 45da1b0 commit e7b3422
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/form_model/model.rb
Expand Up @@ -33,10 +33,10 @@ def initialize(model = bound_class.new, attributes = nil)
end
end

def valid?(type = :model_and_form)
return super if type == :form
def valid?(type = :model_and_form, context = nil)
return super(context) if type == :form
update_data_model!
ok = (super and data_model.valid?)
ok = (super(context) and data_model.valid?(context))
merge_data_model_errors! unless ok
ok
end
Expand All @@ -51,8 +51,8 @@ def bound_class
self.class.bound_class
end

def save
valid? ? data_model.save : false
def save(options = {})
valid?(options) ? data_model.save(options) : false
end

def form_valid?
Expand Down Expand Up @@ -85,14 +85,13 @@ def to_path
end

def update_data_model!
unless data_model
@data_model = bound_class.new
if data_model
attrs = attributes.slice(*data_model_attribute_names).stringify_keys
apply_mappers_to_model!(attrs)
self.instance_exec(&before_write_block) unless self.class.before_write_block.nil?
data_model.write_attributes(attrs)
data_model
end
attrs = attributes.slice(*data_model_attribute_names).stringify_keys
apply_mappers_to_model!(attrs)
self.instance_exec(&before_write_block) unless self.class.before_write_block.nil?
data_model.write_attributes(attrs)
data_model
end

def respond_to?(method_sym, include_private = false)
Expand Down

0 comments on commit e7b3422

Please sign in to comment.