Sha256: bb8e2df8585d85291929f268e9fe4c01dd45018a148d730aeb26908175099965

Contents?: true

Size: 1.98 KB

Versions: 31

Compression:

Stored size: 1.98 KB

Contents

describe "Prime::AssociationCollection" do
   before do
    MotionPrime::Store.connect
  end

  after do
    MotionPrime::Store.shared_store.clear
  end

  describe "#new" do
    before do
      @organization = Organization.new
      @project = @organization.projects.new(title: 'test')
    end

    it "should instanciate model with given attributes" do
      @project.title.should == 'test'
    end

    it "should add model to association collection" do
      @organization.projects.include?(@project).should.be.true
    end
  end

  describe "#add" do
    before do
      @organization = Organization.new
      @project = Project.new(title: 'test')
      @organization.projects.add(@project)
    end

    it "should add model to association collection" do
      @organization.projects.include?(@project).should.be.true
    end
  end

  describe "#all" do
    before do
      @organization = Organization.new
      project = Project.new(title: 'test 1')
      @organization.projects.add(project)
      project = Project.new(title: 'test 2')
      @organization.projects.add(project)
    end

    it "should return all records" do
      @organization.projects.all.count.should == 2
    end
  end

  describe "#find" do
    before do
      @organization = Organization.new
      project = Project.create(title: 'test 1')
      @organization.projects.add(project)
      project = Project.create(title: 'test 2')
      @organization.projects.add(project)
      @organization.save
    end

    it "should return saved records by first hash" do
      @organization.projects.find(title: 'test 1').count.should == 1
    end
  end

  describe "#filter" do
    before do
      @organization = Organization.new
      project = Project.new(title: 'test 1')
      @organization.projects.add(project)
      project = Project.new(title: 'test 2')
      @organization.projects.add(project)
    end

    it "should return saved records by first hash" do
      @organization.projects.filter(title: 'test 1').count.should == 1
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
motion-prime-1.0.7 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.6 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.5 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.4 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.3 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.2 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.1 spec/unit/models/association_collection_spec.rb
motion-prime-1.0.0 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.9.2 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.9.1 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.9 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.8 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.7 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.6 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.5 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.4 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.3 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.2 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.1 spec/unit/models/association_collection_spec.rb
motion-prime-0.9.0 spec/unit/models/association_collection_spec.rb