Sha256: fd870b25abb58f93f1be4ffd1118d813154dd175386b248f45e653c387797f1b

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

RSpec::Matchers.define :invalidate do
  match do |actual|
    actual.save.should == false
    actual.errors[:base].should == ["Access denied"]
  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

14 entries across 14 versions & 1 rubygems

Version Path
protector-0.5.3 spec/spec_helpers/adapters/active_record.rb
protector-0.5.2 spec/spec_helpers/adapters/active_record.rb
protector-0.5.1 spec/spec_helpers/adapters/active_record.rb
protector-0.4.1 spec/spec_helpers/adapters/active_record.rb
protector-0.4.0 spec/spec_helpers/adapters/active_record.rb
protector-0.3.3 spec/spec_helpers/adapters/active_record.rb
protector-0.3.2 spec/spec_helpers/adapters/active_record.rb
protector-0.3.1 spec/spec_helpers/adapters/active_record.rb
protector-0.3.0 spec/spec_helpers/adapters/active_record.rb
protector-0.3.0.beta.2 spec/spec_helpers/adapters/active_record.rb
protector-0.2.4 spec/spec_helpers/adapters/active_record.rb
protector-0.2.3 spec/spec_helpers/adapters/active_record.rb
protector-0.2.2 spec/spec_helpers/adapters/active_record.rb
protector-0.2.1 spec/spec_helpers/adapters/active_record.rb