Sha256: e26b8cc4a44e1e5af3f6a2f017447e448c55dab5173a4e8214361c7c13fc69f4
Contents?: true
Size: 1.48 KB
Versions: 26
Compression:
Stored size: 1.48 KB
Contents
module ModelFactories def create_source(custom={}) create_model!(DataCatalog::Source, custom, { :title => "Healthcare Spending Data", :url => "http://data.gov/details/23", }) end def create_category(custom={}) create_model!(DataCatalog::Category, custom, { :name => "Sample Category", }) end def create_categorization(custom={}) create_model!(DataCatalog::Categorization, custom, { :source_id => "", :category_id => "", }) end def create_note(custom={}) create_model!(DataCatalog::Note, custom, { :text => "Sample Note", :user_id => "", }) end def create_user(custom={}) create_model!(DataCatalog::User, custom, { :name => "Sample User", :email => "sample.user@inter.net", :role => "basic", }) end # ----- def new_usage(custom={}) new_model!(DataCatalog::Usage, custom, { :title => "Sample Usage", :url => "http://inter.net/article/100", :description => "Citation from the internet", }) end protected def create_model!(klass, custom, required) model = klass.create(required.merge(custom)) unless model.valid? raise "Invalid #{klass}: #{model.errors.errors.inspect}" end model end def new_model!(klass, custom, required) model = klass.new(required.merge(custom)) unless model.valid? raise "Invalid #{klass}: #{model.errors.errors.inspect}" end model end end
Version data entries
26 entries across 26 versions & 1 rubygems