Permalink
Browse files

Merge pull request #4705 from varyonic/fix-4533-filter-date-bounds

Fix #4533, use custom Ransack predicate for datetime, not date columns.
  • Loading branch information...
2 parents cf291ad + a4b1f69 commit 793ce0744712fcc1692d68481ad26e207cbd7c08 @timoschilling timoschilling committed on GitHub Jan 11, 2017
@@ -14,7 +14,7 @@ Feature: Development Reloading
ActiveAdmin.register Post do
if Rails::VERSION::MAJOR >= 4
permit_params :custom_category_id, :author_id, :title,
- :body, :position, :published_at, :starred
+ :body, :position, :published_date, :starred
end
end
"""
@@ -12,7 +12,7 @@ Feature: Edit Page
ActiveAdmin.register Post do
if Rails::VERSION::MAJOR >= 4
permit_params :custom_category_id, :author_id, :title,
- :body, :position, :published_at, :starred
+ :body, :position, :published_date, :starred
end
end
"""
@@ -34,15 +34,15 @@ Feature: Edit Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :category, :author, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :category, :author, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form do |f|
f.inputs "Your Post" do
f.input :title
f.input :body
end
f.inputs "Publishing" do
- f.input :published_at
+ f.input :published_date
end
f.actions
end
@@ -63,15 +63,15 @@ Feature: Edit Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :category, :author, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :category, :author, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form :html => {} do |f|
f.inputs "Your Post" do
f.input :title
f.input :body
end
f.inputs "Publishing" do
- f.input :published_at
+ f.input :published_date
end
f.actions
end
@@ -102,7 +102,7 @@ Feature: Edit Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :category, :author, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :category, :author, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form :partial => "form"
end
@@ -9,13 +9,13 @@ Feature: Index Filtering
When I am on the index page for posts
Then I should see "Displaying all 3 Posts"
And I should see the following filters:
- | Author | select |
- | Category | select |
- | Title | string |
- | Body | string |
- | Published at | date range |
- | Created at | date range |
- | Updated at | date range |
+ | Author | select |
+ | Category | select |
+ | Title | string |
+ | Body | string |
+ | Published date | date range |
+ | Created at | date range |
+ | Updated at | date range |
When I fill in "Title" with "Hello World 2"
And I press "Filter"
@@ -12,7 +12,7 @@ Feature: Format as CSV
When I am on the index page for posts
And I follow "CSV"
And I should download a CSV file for "posts" containing:
- | Id | Title | Body | Published at | Position | Starred | Created at | Updated at |
+ | Id | Title | Body | Published date | Position | Starred | Created at | Updated at |
| \d+ | Hello World | | | | | (.*) | (.*) |
Scenario: Default with alias
@@ -24,7 +24,7 @@ Feature: Format as CSV
When I am on the index page for my_articles
And I follow "CSV"
And I should download a CSV file for "my-articles" containing:
- | Id | Title | Body | Published at | Position | Starred | Created at | Updated at |
+ | Id | Title | Body | Published date | Position | Starred | Created at | Updated at |
Scenario: With CSV format customization
Given a configuration of:
@@ -218,13 +218,13 @@ Feature: Index as Table
ActiveAdmin.register Post do
index do
column :author_id do end
- column 'published_at' do end
+ column 'published_date' do end
column :category do end
end
end
"""
Then I should see a sortable table header with "Author"
- Then I should see a sortable table header with "published_at"
+ Then I should see a sortable table header with "published_date"
Then I should not see a sortable table header with "Category"
Scenario: Columns with block are not sortable by when sortable option equals to false
@@ -234,12 +234,12 @@ Feature: Index as Table
ActiveAdmin.register Post do
index do
column :author_id, sortable: false do end
- column 'published_at', sortable: false do end
+ column 'published_date', sortable: false do end
end
end
"""
Then I should not see a sortable table header with "Author"
- Then I should not see a sortable table header with "published_at"
+ Then I should not see a sortable table header with "published_date"
Scenario: Sorting
Given a post with the title "Hello World" and body "From the body" exists
@@ -250,12 +250,12 @@ Feature: Index as Table
"""
When I am on the index page for posts
Then I should see the "index_table_posts" table:
- | [ ] | Id | Title | Body | Published At | Position | Starred | Created At | Updated At | |
+ | [ ] | Id | Title | Body | Published Date | Position | Starred | Created At | Updated At | |
| [ ] | 2 | Bye bye world | Move your... | | | No | /.*/ | /.*/ | ViewEditDelete |
| [ ] | 1 | Hello World | From the body | | | No | /.*/ | /.*/ | ViewEditDelete |
When I follow "Id"
Then I should see the "index_table_posts" table:
- | [ ] | Id | Title | Body | Published At | Position | Starred | Created At | Updated At | |
+ | [ ] | Id | Title | Body | Published Date | Position | Starred | Created At | Updated At | |
| [ ] | 1 | Hello World | From the body | | | No | /.*/ | /.*/ | ViewEditDelete |
| [ ] | 2 | Bye bye world | Move your... | | | No | /.*/ | /.*/ | ViewEditDelete |
@@ -17,7 +17,7 @@ Feature: Index Scope To
# Set up some scopes
scope :all, default: true
scope :published do |posts|
- posts.where "published_at IS NOT NULL"
+ posts.where "published_date IS NOT NULL"
end
end
"""
@@ -85,7 +85,7 @@ Feature: Index Scoping
ActiveAdmin.register Post do
scope :all, :default => true
scope :published do |posts|
- posts.where("published_at IS NOT NULL")
+ posts.where("published_date IS NOT NULL")
end
end
"""
@@ -108,7 +108,7 @@ Feature: Index Scoping
ActiveAdmin.register Post do
scope :all, :default => true
scope :published do |posts|
- posts.where("published_at IS NOT NULL")
+ posts.where("published_date IS NOT NULL")
end
end
"""
@@ -215,7 +215,7 @@ Feature: Index Scoping
ActiveAdmin.register Post do
scope :all, :default => true
scope :published do |posts|
- posts.where("published_at IS NOT NULL")
+ posts.where("published_date IS NOT NULL")
end
index do
@@ -11,7 +11,7 @@ Feature: New Page
ActiveAdmin.register Post do
if Rails::VERSION::MAJOR >= 4
permit_params :custom_category_id, :author_id, :title,
- :body, :position, :published_at, :starred
+ :body, :position, :published_date, :starred
end
end
"""
@@ -34,15 +34,15 @@ Feature: New Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :custom_category_id, :author_id, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :custom_category_id, :author_id, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form do |f|
f.inputs "Your Post" do
f.input :title
f.input :body
end
f.inputs "Publishing" do
- f.input :published_at
+ f.input :published_date
end
f.actions
end
@@ -70,7 +70,7 @@ Feature: New Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :custom_category_id, :author_id, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :custom_category_id, :author_id, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form :partial => "form"
end
@@ -87,7 +87,7 @@ Feature: New Page
Given a configuration of:
"""
ActiveAdmin.register Post do
- permit_params :custom_category_id, :author_id, :title, :body, :published_at, :starred if Rails::VERSION::MAJOR >= 4
+ permit_params :custom_category_id, :author_id, :title, :body, :published_date, :starred if Rails::VERSION::MAJOR >= 4
form do |f|
f.inputs "Your Post" do
@@ -98,7 +98,7 @@ Feature: New Page
f.input :body
end
f.inputs "Publishing" do
- f.input :published_at
+ f.input :published_date
end
f.actions
end
@@ -11,7 +11,7 @@ Feature: Renamed Resource
ActiveAdmin.register Blog::Post, as: 'Post' do
if Rails::VERSION::MAJOR >= 4
permit_params :custom_category_id, :author_id, :title,
- :body, :position, :published_at, :starred
+ :body, :position, :published_date, :starred
end
end
"""
@@ -11,7 +11,7 @@ def create_user(name, type = 'User')
category = Category.where(name: category_name).first_or_create if category_name
title ||= "Hello World %i"
count.times do |i|
- Post.create! title: title % i, body: body, author: author, published_at: published, custom_category_id: category.try(:id), starred: starred
+ Post.create! title: title % i, body: body, author: author, published_date: published, custom_category_id: category.try(:id), starred: starred
end
end
@@ -15,12 +15,12 @@ def to_html
end
def gt_input_name
- "#{method}_gteq_date"
+ column && column.type == :date ? "#{method}_gteq" : "#{method}_gteq_datetime"
end
alias :input_name :gt_input_name
def lt_input_name
- "#{method}_lteq_date"
+ column && column.type == :date ? "#{method}_lteq" : "#{method}_lteq_datetime"
end
def input_html_options(input_name = gt_input_name)
View
@@ -10,11 +10,11 @@
config.add_predicate old, arel_predicate: current
end
- config.add_predicate 'gteq_date',
+ config.add_predicate 'gteq_datetime',
arel_predicate: 'gteq',
formatter: ->(v) { v.beginning_of_day }
- config.add_predicate 'lteq_date',
+ config.add_predicate 'lteq_datetime',
arel_predicate: 'lt',
formatter: ->(v) { v + 1.day }
end
@@ -4,7 +4,7 @@
copy_file File.expand_path('../templates/manifest.js', __FILE__), 'app/assets/config/manifest.js', force: true
end
-generate :model, 'post title:string body:text published_at:datetime author_id:integer ' +
+generate :model, 'post title:string body:text published_date:date author_id:integer ' +
'position:integer custom_category_id:integer starred:boolean foo_id:integer'
create_file 'app/models/post.rb', <<-RUBY.strip_heredoc, force: true
class Post < ActiveRecord::Base
@@ -15,13 +15,13 @@ class Post < ActiveRecord::Base
accepts_nested_attributes_for :taggings
unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
- attr_accessible :id, :title, :body, :starred, :author, :position, :published_at, :author_id, :custom_category_id, :category
+ attr_accessible :id, :title, :body, :starred, :author, :position, :published_date, :author_id, :custom_category_id, :category
end
end
RUBY
copy_file File.expand_path('../templates/post_decorator.rb', __FILE__), 'app/models/post_decorator.rb'
-generate :model, 'blog/post title:string body:text published_at:datetime author_id:integer ' +
+generate :model, 'blog/post title:string body:text published_date:date author_id:integer ' +
'position:integer custom_category_id:integer starred:boolean foo_id:integer'
create_file 'app/models/blog/post.rb', <<-RUBY.strip_heredoc, force: true
class Blog::Post < ActiveRecord::Base
@@ -32,7 +32,7 @@ class Blog::Post < ActiveRecord::Base
accepts_nested_attributes_for :taggings
unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
- attr_accessible :title, :body, :starred, :author, :position, :published_at, :author_id, :custom_category_id, :category
+ attr_accessible :title, :body, :starred, :author, :position, :published_date, :author_id, :custom_category_id, :category
end
end
RUBY
@@ -21,21 +21,21 @@
inject_into_file 'app/admin/post.rb', <<-RUBY, after: "ActiveAdmin.register Post do\n"
if Rails::VERSION::MAJOR >= 4
- permit_params [:custom_category_id, :author_id, :title, :body, :published_at, :position, :starred]
+ permit_params [:custom_category_id, :author_id, :title, :body, :published_date, :position, :starred]
end
scope :all, default: true
scope :drafts do |posts|
- posts.where(["published_at IS NULL"])
+ posts.where(["published_date IS NULL"])
end
scope :scheduled do |posts|
- posts.where(["posts.published_at IS NOT NULL AND posts.published_at > ?", Time.now.utc])
+ posts.where(["posts.published_date IS NOT NULL AND posts.published_date > ?", Time.now.utc])
end
scope :published do |posts|
- posts.where(["posts.published_at IS NOT NULL AND posts.published_at < ?", Time.now.utc])
+ posts.where(["posts.published_date IS NOT NULL AND posts.published_date < ?", Time.now.utc])
end
scope :my_posts do |posts|
@@ -61,11 +61,11 @@
1_000.times do |i|
user = users[i % users.size]
cat = categories[i % categories.size]
- published_at = published_at_values[i % published_at_values.size]
+ published = published_at_values[i % published_at_values.size]
Post.create title: "Blog Post \#{i}",
body: "Blog post \#{i} is written by \#{user.username} about \#{cat.name}",
category: cat,
- published_at: published_at,
+ published_date: published,
author: user,
starred: true
end
@@ -189,8 +189,8 @@
context "build csv using the supplied order" do
before do
- @post1 = Post.create!(title: "Hello1", published_at: Date.today - 2.day )
- @post2 = Post.create!(title: "Hello2", published_at: Date.today - 1.day )
+ @post1 = Post.create!(title: "Hello1", published_date: Date.today - 2.day )
+ @post2 = Post.create!(title: "Hello2", published_date: Date.today - 1.day )
end
let(:dummy_controller) {
class DummyController
@@ -199,7 +199,7 @@ def find_collection(*)
end
def collection
- Post.order('published_at DESC')
+ Post.order('published_date DESC')
end
def apply_decorator(resource)
@@ -215,7 +215,7 @@ def view_context
ActiveAdmin::CSVBuilder.new do
column "id"
column "title"
- column "published_at"
+ column "published_date"
end
end
Oops, something went wrong.

0 comments on commit 793ce07

Please sign in to comment.