Sha256: f03b043e34ed3726955b7bd202ebc8bccf262760cd1b416ec0e1a3b6fe16bcec

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'
require "#{File.dirname(__FILE__)}/../support/tables_spec_helper"
require "#{File.dirname(__FILE__)}/../support/shared_example_spec_helper_for_time_key"

module Partitioned

  describe ByCreatedAt do

    include TablesSpecHelper

    module CreatedAt
      class Employee < Partitioned::ByCreatedAt
        belongs_to :company, :class_name => 'Company'

        partitioned do |partition|
          partition.index :id, :unique => true
          partition.foreign_key :company_id
        end
      end # Employee
    end # CreatedAt

    before(:all) do
      @employee = CreatedAt::Employee
      create_tables
      dates = @employee.partition_generate_range(DATE_NOW,
                                                 DATE_NOW + 7.days)
      @employee.create_new_partition_tables(dates)
      ActiveRecord::Base.connection.execute <<-SQL
        insert into employees_partitions.
          p#{DATE_NOW.at_beginning_of_week.strftime('%Y%m%d')}
          (company_id,name) values (1,'Keith');
      SQL
    end

    after(:all) do
      drop_tables
    end

    let(:class_by_created_at) { ::Partitioned::ByCreatedAt }

    describe "model is abstract class" do

      it "returns true" do
        expect(class_by_created_at.abstract_class).to be_truthy
      end

    end # model is abstract class

    describe "#partition_time_field" do

      it "returns :created_at" do
        expect(class_by_created_at.partition_time_field).to eq(:created_at)
      end

    end # #partition_time_field

    it_should_behave_like "check that basic operations with postgres works correctly for time key", CreatedAt::Employee

  end # ByCreatedAt

end # Partitioned

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
partitioned-2.1.0 spec/partitioned/by_created_at_spec.rb
partitioned-2.0.0 spec/partitioned/by_created_at_spec.rb