Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ More exceptions when things fail

  • Loading branch information...
commit 4251a89b9a750d98259d3f2d7b7809a93673240c 1 parent d345d34
Kaspar Schiess authored
12 lib/floor_manager/employee.rb
View
@@ -17,7 +17,8 @@ def initialize(klass_name)
# Build this employee in memory.
#
def build(floor, overrides)
- produce_instance.tap { |i| apply_attributes(i, :none, floor, overrides) }
+ produce_instance.tap { |i|
+ apply_attributes(i, :none, floor, overrides) }
end
# Create this employee in the database.
@@ -25,11 +26,16 @@ def build(floor, overrides)
def create(floor, overrides)
produce_instance.tap { |i|
apply_attributes(i, :none, floor, overrides)
- i.save!
+
+ unless i.valid?
+ err_msgs = i.errors.to_a.join(',')
+ fail "#{@klass_name.inspect} not constructed valid: #{err_msgs}"
+ end
+ i.save or fail "Could not create instance of #{@klass_name.inspect}."
unless @attributes[:after_create].empty?
apply_attributes(i, :after_create, floor)
- i.save!
+ i.save or fail "Could not save after_create."
end
}
end
3  lib/floor_manager/employee/attribute_action.rb
View
@@ -42,7 +42,8 @@ def initialize(field, create_args)
@create_args = create_args
end
def apply(obj, floor, employee)
- set(obj, floor.build(*@create_args))
+ assoc_obj = floor.build(*@create_args)
+ set(obj, assoc_obj)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.