-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add administrate default format #2781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
goosys
wants to merge
1
commit into
thoughtbot:main
Choose a base branch
from
goosys:add-administrate_default-format
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,12 +6,39 @@ | |
| let(:formats) do | ||
| { | ||
| date: { | ||
| formats: {default: "%m/%d/%Y", short: "%b %d"}, | ||
| formats: { | ||
| default: "%m/%d/%Y", | ||
| short: "%b %d", | ||
| administrate_date_default: "%m/%d, %Y" | ||
| }, | ||
| 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", short: "%d %b"} | ||
| formats: { | ||
| default: "%a, %b %-d, %Y at %r", | ||
| short: "%d %b %H:%M", | ||
| administrate_datetime_default: "%a, %b %-d, %Y, %r", | ||
| administrate_time_default: "%I:%M%p" | ||
| } | ||
| } | ||
| } | ||
| end | ||
| let(:formats_without_administrate_default) 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 | ||
|
|
@@ -21,11 +48,11 @@ | |
| with_translations(:en, formats) do | ||
| field = Administrate::Field::Date | ||
| .new(:start_date, start_date, :show) | ||
| expect(field.date).to eq("12/25/2015") | ||
| expect(field.date).to eq("12/25, 2015") | ||
| end | ||
| end | ||
|
|
||
| context "with `prefix` option" do | ||
| context "with `format` option" do | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not meant to cover the |
||
| it "displays the date in the requested format" do | ||
| options_field = Administrate::Field::Date | ||
| .with_options(format: :short) | ||
|
|
@@ -46,5 +73,34 @@ | |
| end | ||
| end | ||
| end | ||
|
|
||
| context "without `format` option" do | ||
| it "falls back to default format if administrate_date_default is missing" do | ||
| options_field = Administrate::Field::Date | ||
| field = options_field.new(:start_date, start_date, :show) | ||
|
|
||
| with_translations(:en, formats_without_administrate_default) do | ||
| expect(field.date).to eq("12/25/2015") | ||
| end | ||
| end | ||
|
|
||
| it "falls back to static format (%Y-%m-%d) if locale formats are missing" do | ||
| options_field = Administrate::Field::Date | ||
| field = options_field.new(:start_date, start_date, :show) | ||
|
|
||
| with_translations(:unformatted_locale, {}) do | ||
| available_locales = I18n.available_locales | ||
| locale = I18n.locale | ||
| begin | ||
| I18n.available_locales = [:unformatted_locale] | ||
| I18n.locale = :unformatted_locale | ||
| expect(field.date).to eq("2015-12-25") | ||
| ensure | ||
| I18n.available_locales = available_locales | ||
| I18n.locale = locale | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In environments where
rails-i18nis installed,formats.defaultshould always be present, but I've added an additional fallback just in case.