Sha256: 2820bdd5db3a7815ea683efe5af49b11075a5e64c6a30b466bc70cf4a6bb6451

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require_relative "test_helper"

class TestDateSupercharger < Minitest::Test
  extend Minitest::Spec::DSL

  let(:now) { DateTime.now }
  let(:monday) { DateTime.now.beginning_of_week }
  let(:tuesday) { monday + 1.day }
  let(:wednesday) { monday + 2.day }
  let(:thursday) { monday + 3.day }
  let(:friday) { monday + 4.day }
  let(:saturday) { monday + 5.day }
  let(:sunday) { monday + 6.day }

  before do
    unless ActiveRecord::Base.connected?
      establish_connection
      days = [monday,tuesday,wednesday,thursday,friday,saturday,sunday]
      days.each do |day|
        create({city: "Bogota",visit_date: day})
      end
    end
  end

  describe "ActiveRecord has established a connection to the database" do

    describe "#_after" do
      it "should not include be inclusive" do
        assert_equal 6, Visit.visit_date_after(monday).count
      end
    end

    describe "#_after_or_at" do
      it "should be inclusive" do
        assert_equal 7, Visit.visit_date_after_or_at(monday).count
      end
    end

    describe "#_before" do
      it "should not include be inclusive" do
        assert_equal 6, Visit.visit_date_before(sunday).count
      end
    end

    describe "#_before_or_at" do
      it "should be inclusive" do
        assert_equal 7, Visit.visit_date_before_or_at(sunday).count
      end
    end

  end

  describe "ActiveRecord has not established a connection to the database" do
    before do
      ActiveRecord::Base.remove_connection
    end
    it "should not raise exception" do
      assert_equal false, Visit.respond_to?(:unexisting_method)
    end

  end

  private

    def create(attributes, count = 1)
      count.times { Visit.create!(attributes) }
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
date_supercharger-0.0.1 test/date_supercharger_test.rb