-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to create the time scopes for time-related columns
- Loading branch information
Showing
6 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe ActiveRecord::TimeScope do | ||
describe "::create_time_scopes" do | ||
subject { | ||
create_tmp_model foo_at: :datetime, bar_on: :date, xxx_time: :datetime, yyy_date: :date, zzz: :date do | ||
create_time_scopes | ||
end | ||
} | ||
it do | ||
%w(foo bar xxx yyy).each do |key| | ||
is_expected.to respond_to "#{key}_before" | ||
is_expected.to respond_to "#{key}_after" | ||
is_expected.to respond_to "#{key}_within" | ||
end | ||
%w(zzz).each do |key| | ||
is_expected.not_to respond_to "#{key}_before" | ||
is_expected.not_to respond_to "#{key}_after" | ||
is_expected.not_to respond_to "#{key}_within" | ||
end | ||
end | ||
end | ||
describe "::create_time_scope" do | ||
subject { | ||
create_tmp_model zzz: :date do | ||
create_time_scope :www, :zzz | ||
end | ||
} | ||
it do | ||
is_expected.to respond_to :www_before | ||
is_expected.to respond_to :www_after | ||
is_expected.to respond_to :www_within | ||
is_expected.not_to respond_to :zzz_before | ||
is_expected.not_to respond_to :zzz_after | ||
is_expected.not_to respond_to :zzz_within | ||
end | ||
end | ||
describe "::create_time_range_scope" do | ||
subject { | ||
create_tmp_model aaa: :date, bbb: :date do | ||
create_time_range_scope :xxx, :aaa, :bbb | ||
end | ||
} | ||
it do | ||
is_expected.to respond_to :xxx_before | ||
is_expected.to respond_to :xxx_after | ||
is_expected.to respond_to :xxx_within | ||
is_expected.not_to respond_to :aaa_before | ||
is_expected.not_to respond_to :aaa_after | ||
is_expected.not_to respond_to :aaa_within | ||
is_expected.not_to respond_to :bbb_before | ||
is_expected.not_to respond_to :bbb_after | ||
is_expected.not_to respond_to :bbb_within | ||
end | ||
end | ||
end |