Sha256: 5fe6dc6ab116ae9431d782be2adc28f5053660bab588be83dba5e8fc521aa118

Contents?: true

Size: 1.46 KB

Versions: 10

Compression:

Stored size: 1.46 KB

Contents

require 'active_record'
require 'flipper/model/active_record'

# Turn off migration logging for specs
ActiveRecord::Migration.verbose = false

RSpec.describe Flipper::Model::ActiveRecord do
  before(:all) do
    ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
  end

  before(:each) do
    ActiveRecord::Base.connection.execute <<-SQL
      CREATE TABLE users (
        id integer PRIMARY KEY,
        name string NOT NULL,
        age integer,
        is_confirmed boolean,
        created_at datetime NOT NULL,
        updated_at datetime NOT NULL
      )
    SQL
  end

  after(:each) do
    ActiveRecord::Base.connection.execute("DROP table IF EXISTS `users`")
  end

  class User < ActiveRecord::Base
    include Flipper::Model::ActiveRecord
  end

  class Admin < User
  end

  describe "flipper_id" do
    it "returns class name and id" do
      expect(User.new(id: 1).flipper_id).to eq("User;1")
    end

    it "uses base class name" do
      expect(Admin.new(id: 2).flipper_id).to eq("User;2")
    end
  end

  describe "flipper_properties" do
    subject { User.create!(name: "Test", age: 22, is_confirmed: true) }

    it "includes all attributes" do
      expect(subject.flipper_properties).to eq({
        "type" => "User",
        "id" => subject.id,
        "name" => "Test",
        "age" => 22,
        "is_confirmed" => true,
        "created_at" => subject.created_at,
        "updated_at" => subject.updated_at
      })
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
flipper-1.3.2 spec/flipper/model/active_record_spec.rb
flipper-1.3.1 spec/flipper/model/active_record_spec.rb
flipper-1.3.0 spec/flipper/model/active_record_spec.rb
flipper-1.3.0.pre spec/flipper/model/active_record_spec.rb
flipper-1.2.2 spec/flipper/model/active_record_spec.rb
flipper-1.2.1 spec/flipper/model/active_record_spec.rb
flipper-1.2.0 spec/flipper/model/active_record_spec.rb
flipper-1.1.2 spec/flipper/model/active_record_spec.rb
flipper-1.1.1 spec/flipper/model/active_record_spec.rb
flipper-active_record-1.1.0 spec/flipper/model/active_record_spec.rb