Sha256: 10cba48ed6ecfdf57e7296cffbae22a419dc537c7d72ad5b6605c075da55fdae

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

require 'helper'

class TestReadonly < Test::Unit::TestCase
  context "Some static model" do
    setup do
      ActiveRecord::Base.connection.create_table :static_things, :force => true do |t|
        t.string :name
      end
      ActiveRecord::Base.connection.execute("insert into static_things (name) values ('Blah thing')")
      class StaticThing < ActiveRecord::Base
        include ActiveRecord::ReadonlyModel
      end
    end

    teardown do
      ActiveRecord::Base.connection.drop_table :static_things
    end

    should "prevent destroy" do
      before_count = StaticThing.count
      assert_raise ActiveRecord::ReadOnlyRecord do
        StaticThing.first.destroy
      end
      assert_equal(before_count, StaticThing.count)
    end

    should "prevent update" do
      thing = StaticThing.first
      thing.name = 'something different'
      assert_raise ActiveRecord::ReadOnlyRecord do
        thing.save
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-readonly_model-0.0.2 test/test_readonly.rb