Sha256: c1813ac40c39ca4ce1cef3e80e1fe5c2cff15b2d79a4c35a33dad339ceea7b32

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 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
      it "should raise an ArgumentError when receives more than one param" do
        assert_raises(ArgumentError) { Visit.visit_date_after(monday,:additional_argument) }
      end
      it "should raise an ArgumentError when receives no params" do
        assert_raises(ArgumentError) { Visit.visit_date_after() }
      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.2 test/date_supercharger_test.rb