Sha256: 3663edd149ef40e5f3aa37effb020fb2f1669559ada9a525201b3095d3b96097

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

load(File.dirname(__FILE__) + '/schema.rb')

describe SeedFu::Seeder do
  it "should create a model if one doesn't exist" do
    SeededModel.seed(:id) do |s|
      s.id = 1
      s.login = "bob"
      s.first_name = "Bob"
      s.last_name = "Bobson"
      s.title = "Peon"
    end
    
    bob = SeededModel.find_by_id(1)
    bob.first_name.should == "Bob"
    bob.last_name.should == "Bobson"
  end
  
  it "should be able to handle multiple constraints" do
    SeededModel.seed(:title, :login) do |s|
      s.login = "bob"
      s.title = "Peon"
      s.first_name = "Bob"
    end
    
    SeededModel.count.should == 1
    
    SeededModel.seed(:title, :login) do |s|
      s.login = "frank"
      s.title = "Peon"
      s.first_name = "Frank"
    end
    
    SeededModel.count.should == 2
    
    SeededModel.find_by_login("bob").first_name.should == "Bob"
    SeededModel.seed(:title, :login) do |s|
      s.login = "bob"
      s.title = "Peon"
      s.first_name = "Steve"
    end
    SeededModel.find_by_login("bob").first_name.should == "Steve"
  end
  
  #it "should raise an error if constraints are not unique" do
  #  SeededModel.create(:login => "bob", :first_name => "Bob", :title => "Peon")
  #  SeededModel.create(:login => "bob", :first_name => "Robert", :title => "Manager")
  #  
  #  SeededModel.seed(:login) do |s|
  #    s.login = "bob"
  #    s.title = "Overlord"
  #  end
  #end
  
  it "should default to an id constraint"
  it "should update, not create, if constraints are met"
  it "should require that all constraints are defined"
  it "should raise an error if validation fails"
  it "should retain fields that aren't specifically altered in the seeding"
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jcnetdev-seed-fu-1.0.20080704 spec/seed_fu_spec.rb
jcnetdev-seed-fu-1.0.200807042 spec/seed_fu_spec.rb