Sha256: 3e343c7021ef45dad52779228bfbbd0d0bab4d43567addc35655da5d988290a1

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

require "active_record"

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

ActiveRecord::Base.connection.create_table :econfig_options do |t|
  t.string :key, :null => false
  t.string :value
end

require "econfig/active_record"

describe Econfig::ActiveRecord do
  let(:backend) { Econfig::ActiveRecord.new }
  around do |example|
    ActiveRecord::Base.transaction do
      example.run
      raise ActiveRecord::Rollback
    end
  end
  describe "#get" do
    it "fetches a previously set option" do
      backend.set("foo", "bar")
      backend.get("foo").should == "bar"
    end

    it "fetches a previously persisted option" do
      Econfig::ActiveRecord::Option.create!(:key => "foo", :value => "bar")
      backend.get("foo").should == "bar"
    end

    it "returns nil if option is not set" do
      backend.get("foo").should be_nil
    end
  end

  describe "#set" do
    it "persists keys to database" do
      backend.set("foo", "bar")
      Econfig::ActiveRecord::Option.find_by_key!("foo").value.should == "bar"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
econfig-2.0.0 spec/active_record_spec.rb
econfig-1.0.2 spec/active_record_spec.rb
econfig-1.0.1 spec/active_record_spec.rb
econfig-1.0.0 spec/active_record_spec.rb
econfig-0.1.1 spec/active_record_spec.rb
econfig-0.1.0 spec/active_record_spec.rb