16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/mocked_fixtures/mocks/rspec.rb', line 16
def mock_model_with_attributes(model_class, options_and_stubs = {})
if options_and_stubs.delete(:all_attributes)
schema = MockedFixtures::SchemaParser.load_schema
table = model_class.table_name
schema[table][:columns].each { |column|
unless options_and_stubs.has_key?(column[0].to_sym) || column[0] == model_class.primary_key
options_and_stubs[column[0].to_sym] = nil
end
}
end
if options_and_stubs.delete(:add_errors)
errors = []
errors.stub!(:count).and_return(0)
errors.stub!(:on).and_return(nil)
options_and_stubs.reverse_merge!(:errors => errors)
end
mock_model_without_attributes(model_class, options_and_stubs)
end
|