Sha256: fac0f800cb112b963f65ab6c23b7c8ae8250479f655068c64337d2f63755eefb

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

RSpec::Matchers.define :invalidate do
  match do |actual|
    actual.save.should == false
    actual.errors[:base][0].starts_with?("Access denied to").should == true
  end
end

RSpec::Matchers.define :validate do
  match do |actual|
    actual.class.transaction do
      actual.save.should == true
      raise ActiveRecord::Rollback
    end

    true
  end
end

RSpec::Matchers.define :destroy do
  match do |actual|
    actual.class.transaction do
      actual.destroy.should == actual
      raise ActiveRecord::Rollback
    end

    actual.class.where(id: actual.id).delete_all

    true
  end
end

RSpec::Matchers.define :survive do
  match do |actual|
    actual.class.transaction do
      actual.destroy.should == false
      raise ActiveRecord::Rollback
    end

    actual.class.where(id: actual.id).delete_all

    true
  end
end

def log!
  around(:each) do |e|
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    e.run
    ActiveRecord::Base.logger = nil
  end
end

def assign!(model, fields)
  model.assign_attributes(fields)
end

def read_attribute(model, field)
  model.read_attribute(field)
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
protector-0.7.7 spec/spec_helpers/adapters/active_record.rb
protector-0.7.6 spec/spec_helpers/adapters/active_record.rb
protector-0.7.4 spec/spec_helpers/adapters/active_record.rb
protector-0.7.3 spec/spec_helpers/adapters/active_record.rb
protector-0.7.2 spec/spec_helpers/adapters/active_record.rb
protector-0.7.1 spec/spec_helpers/adapters/active_record.rb
protector-0.7.0 spec/spec_helpers/adapters/active_record.rb
protector-0.6.4 spec/spec_helpers/adapters/active_record.rb
protector-0.6.3 spec/spec_helpers/adapters/active_record.rb
protector-0.6.2 spec/spec_helpers/adapters/active_record.rb
protector-0.6.1 spec/spec_helpers/adapters/active_record.rb
protector-0.6.0 spec/spec_helpers/adapters/active_record.rb
protector-0.6.0.beta.1 spec/spec_helpers/adapters/active_record.rb
protector-0.5.5 spec/spec_helpers/adapters/active_record.rb
protector-0.5.4 spec/spec_helpers/adapters/active_record.rb