Sha256: d834e91d55829d1f3a14a14acd7c5603b03e196898bd42fcf402f42a0b7a2290

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

require "cases/helper_sqlserver"

class ViewTestSQLServer < ActiveRecord::TestCase
  let(:connection) { ActiveRecord::Base.connection }

  describe 'view with default values' do
    before do
      connection.drop_table :view_casing_table rescue nil
      connection.create_table :view_casing_table, force: true do |t|
        t.boolean :Default_Falsey,      null: false, default: false
        t.boolean :Default_Truthy,      null: false, default: true
        t.string  :default_string_null, null: true,  default: nil
        t.string  :default_string,      null: false, default: "abc"
      end

      connection.execute("DROP VIEW IF EXISTS view_casing_table_view;")
      connection.execute <<-SQL
        CREATE VIEW view_casing_table_view AS
              SELECT id AS id,
                     default_falsey      AS falsey,
                     default_truthy      AS truthy,
                     default_string_null AS s_null,
                     default_string      AS s
              FROM view_casing_table
      SQL
    end

    it "default values are correct when column casing used in tables and views are different" do
      klass = Class.new(ActiveRecord::Base) do
        self.table_name = "view_casing_table_view"
      end

      obj = klass.new
      assert_equal false, obj.falsey
      assert_equal true, obj.truthy
      assert_equal "abc", obj.s
      assert_nil   obj.s_null
      assert_equal 0, klass.count

      obj.save!
      assert_equal false, obj.falsey
      assert_equal true, obj.truthy
      assert_equal "abc", obj.s
      assert_nil   obj.s_null
      assert_equal 1, klass.count
    end
  end

  describe 'identity insert' do
    it "identity insert works with views" do
      assert_difference("SSTestCustomersView.count", 1) do
        SSTestCustomersView.create!(id: 5, name: "Bob")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.1.9 test/cases/view_test_sqlserver.rb
activerecord-sqlserver-adapter-7.1.8 test/cases/view_test_sqlserver.rb