Sha256: 54cd1c03976f99a806a34e2c765f77363b705924348adea63706f072dd0f40d0

Contents?: true

Size: 1.84 KB

Versions: 9

Compression:

Stored size: 1.84 KB

Contents

require "spec_helper"
require "scorpion/rails"

describe Scorpion::Rails::ActiveRecord::Relation, type: :model do
  include Scorpion::Rspec::Helper

  let( :criteria ) { Todo.with_scorpion( scorpion ) }

  it "shares scorpion with fetched records" do
    Todo.create! name: "Be awesome"

    expect( criteria.first.scorpion ).to eq scorpion
  end

  it "shares scorpion with chained relations" do
    expect( criteria.where( name: "" ).scorpion ).to be scorpion
  end

  it "shares scorpion with new records" do
    expect( criteria.new.scorpion ).to be scorpion
    expect( criteria.build.scorpion ).to be scorpion
  end

  it "shares scorpion with new records builder block" do
    criteria.new do |todo|
      expect( todo.scorpion ).to be scorpion
    end
  end

  it "shares scorpion with created records" do
    expect( criteria.create.scorpion ).to be scorpion
  end

  it "shares scorpion with created records builder block" do
    criteria.create do |todo|
      expect( todo.scorpion ).to be scorpion
    end
  end

  it "shares scorpion with created! records" do
    expect( criteria.create!.scorpion ).to be scorpion
  end

  it "shares scorpion with created! records builder block" do
    criteria.create! do |todo|
      expect( todo.scorpion ).to be scorpion
    end
  end

  context "find methods" do
    let!( :todo ) { Todo.create! name: "Bill" }

    it "shares scorpion with found records" do
      expect( criteria.find( todo.id ).scorpion ).to be scorpion
    end

    it "shares scorpion with find_by records" do
      expect( criteria.find_by( name: "Bill" ).scorpion ).to be scorpion
    end

    it "shares scorpion with first record" do
      expect( criteria.first.scorpion ).to be scorpion
    end

    it "shares scorpion with enumerated records" do
      criteria.each do |todo|
        expect( todo.scorpion ).to be scorpion
      end
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scorpion-ioc-1.0.10 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.8 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.7 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.6 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.4 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.3 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.2 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.1 spec/lib/scorpion/rails/active_record/relation_spec.rb
scorpion-ioc-1.0.0 spec/lib/scorpion/rails/active_record/relation_spec.rb