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

Version Path
sinatra_resource-0.4.21 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.20 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.19 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.18 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.17 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.16 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.15 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.14 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.13 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.12 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.11 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.10 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.9 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.8 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.7 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.6 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.5 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.4 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.3 examples/datacatalog/test/helpers/lib/model_factories.rb
sinatra_resource-0.4.2 examples/datacatalog/test/helpers/lib/model_factories.rb