Sha256: 5b77a1d4e6eb940fa51a3c4e9d5449ef1a09e8e163202ca3195149d98b9d0324

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rubygems'
require 'active_record'
require 'sudo_attributes'
require 'spec' 

ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

ActiveRecord::Schema.define(:version => 1) do
  create_table :cats, :force => true do |t|
    t.string :name
    t.string :color
    t.integer :age
  end
end

module SudoAttributesTest
  ARGUMENTS = [
    "sudo_attr_protected :name",
    "sudo_attr_accessible :color, :age",
    "attr_protected :name; sudo_attr_protected"
  ]
  
  def self.build_cat_class(argument)

    # Remove the Cat class if it's already been defined in previous run
    Object.class_eval { remove_const "Cat" if const_defined? "Cat" }

    # Create a new Cat class and evaluate 'has_sudo_attributes :arguments
    klass = Class.new(ActiveRecord::Base)
    Object.const_set("Cat", klass)

    Cat.class_eval %{
      validates_presence_of :color
      #{argument}
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sudo_attributes-0.5.2 spec/spec_helper.rb
sudo_attributes-0.5.1 spec/spec_helper.rb
sudo_attributes-0.5.0 spec/spec_helper.rb
sudo_attributes-0.4.0 spec/spec_helper.rb