forked from thoughtbot/administrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorder I18n backends in `with_translations` helper The `with_translations` helper allows translations to be setup for a method under test. A recent change (thoughtbot#772) added a backend chain to ensure this helper won't break other spec by replacing all translations and causing "missing_translations" failures. This changes the order of the I18n backends so that specs will first use the translations provided to the `with_translations` block and then fallback to the default translations. Otherwise, there would be no way to override the default translations in test cases. * Adds format option to DateTime field Updates DateTime field to accept 'format' option which determines the display format of the field. The option can be * A key for the localized date format in the corresponding yaml config file * A strftime format string
- Loading branch information
Showing
5 changed files
with
94 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,82 @@ | ||
require "spec_helper" | ||
require "rails_helper" | ||
require "administrate/field/date_time" | ||
require "support/field_matchers" | ||
|
||
describe Administrate::Field::DateTime do | ||
let(:start_date) { DateTime.parse("2015-12-25 10:15:45") } | ||
let(:formats) do | ||
{ | ||
date: { | ||
formats: { default: "%m/%d/%Y", short: "%b %d" }, | ||
abbr_month_names: Array.new(13) { |i| "Dec" if i == 12 }, | ||
abbr_day_names: Array.new(7) { |i| "Fri" if i == 5 }, | ||
}, | ||
time: { | ||
formats: { default: "%a, %b %-d, %Y at %r", short: "%d %b %H:%M" }, | ||
}, | ||
} | ||
end | ||
|
||
describe "#date" do | ||
it "displays the date" do | ||
with_translations(:en, formats) do | ||
field = Administrate::Field::DateTime. | ||
new(:start_date, start_date, :show) | ||
expect(field.date).to eq("12/25/2015") | ||
end | ||
end | ||
|
||
context "with `prefix` option" do | ||
it "displays the date in the requested format" do | ||
options_field = Administrate::Field::DateTime. | ||
with_options(format: :short) | ||
field = options_field.new(:start_date, start_date, :show) | ||
|
||
with_translations(:en, formats) do | ||
expect(field.date).to eq("Dec 25") | ||
end | ||
end | ||
|
||
it "displays the date using a format string" do | ||
options_field = Administrate::Field::DateTime. | ||
with_options(format: "%Y") | ||
field = options_field.new(:start_date, start_date, :show) | ||
|
||
with_translations(:en, formats) do | ||
expect(field.date).to eq("2015") | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "#datetime" do | ||
it "displays the datetime" do | ||
field = Administrate::Field::DateTime.new(:start_date, start_date, :show) | ||
|
||
with_translations(:en, formats) do | ||
expect(field.datetime).to eq("Fri, Dec 25, 2015 at 10:15:45 AM") | ||
end | ||
end | ||
|
||
context "with `prefix` option" do | ||
it "displays the datetime in the requested format" do | ||
options_field = Administrate::Field::DateTime. | ||
with_options(format: :short) | ||
field = options_field.new(:start_date, start_date, :show) | ||
|
||
with_translations(:en, formats) do | ||
expect(field.datetime).to eq("25 Dec 10:15") | ||
end | ||
end | ||
|
||
it "displays the datetime format string" do | ||
options_field = Administrate::Field::DateTime. | ||
with_options(format: "%H:%M") | ||
field = options_field.new(:start_date, start_date, :show) | ||
|
||
with_translations(:en, formats) do | ||
expect(field.datetime).to eq("10:15") | ||
end | ||
end | ||
end | ||
end | ||
end |
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