[Git][noosfero/noosfero][master] 2 commits: return article with no end date defined
Leandro Nunes
gitlab at mg.gitlab.com
Mon Jul 22 16:21:54 BRT 2019
Leandro Nunes pushed to branch master at Noosfero / noosfero
Commits:
5c117b3f by Leandro Nunes dos Santos at 2019-07-22T17:46:16Z
return article with no end date defined
- - - - -
4cdbbb29 by Leandro Nunes at 2019-07-22T19:21:51Z
Merge branch 'adjust-api-return' into 'master'
return article with no end date defined
See merge request noosfero/noosfero!1703
- - - - -
2 changed files:
- app/api/helpers.rb
- test/api/articles_test.rb
Changes:
=====================================
app/api/helpers.rb
=====================================
@@ -342,7 +342,7 @@ module Api
table_name = class_type.table_name
if class_type.new.is_a?(Event)
- scope = scope.where("#{table_name}.#{attribute} >= ?", from_date) unless from_date.nil?
+ scope = scope.where(" (#{table_name}.#{attribute} >= ?) OR (#{table_name}.#{attribute} iS NULL)", from_date) unless from_date.nil?
scope = scope.where("#{table_name}.#{attribute} <= ?", until_date) unless until_date.nil?
else
scope = scope.where("#{table_name}.created_at >= ?", from_date) if !from_date.nil? && until_date.nil?
=====================================
test/api/articles_test.rb
=====================================
@@ -955,6 +955,32 @@ class ArticlesTest < ActiveSupport::TestCase
assert_equal json.first['id'], article.id
end
+ should 'return event articles until start_date and from end_date' do
+ Article.delete_all
+ fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now + 1, end_date: DateTime.now + 2)
+ article = fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now - 2, end_date: DateTime.now + 1)
+ fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now - 2, end_date: DateTime.now - 1)
+ params[:until_start_date] = DateTime.now
+ params[:from_end_date] = DateTime.now
+ get "/api/v1/articles/?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal 1, json.length
+ assert_equal json.first['id'], article.id
+ end
+
+ should 'return event articles until start_date and from end_date return articles with end_date nil' do
+ Article.delete_all
+ fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now + 1, end_date: DateTime.now + 2)
+ article = fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now - 2)
+ fast_create(Event, :profile_id => user.person.id, :name => "Some thing", start_date: DateTime.now - 2, end_date: DateTime.now - 1)
+ params[:until_start_date] = DateTime.now
+ params[:from_end_date] = DateTime.now
+ get "/api/v1/articles/?#{params.to_query}"
+ json = JSON.parse(last_response.body)
+ assert_equal 1, json.length
+ assert_equal json.first['id'], article.id
+ end
+
should 'return articles from start_date' do
Article.delete_all
article = fast_create(TextArticle, :profile_id => user.person.id, created_at: DateTime.now + 1)
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fa3523fed1ff93a7895509ad66722a7861d6f770...4cdbbb29f713593f8da40978c13aff6bd90d749a
--
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/fa3523fed1ff93a7895509ad66722a7861d6f770...4cdbbb29f713593f8da40978c13aff6bd90d749a
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20190722/1bf59113/attachment-0001.html>
More information about the Noosfero-dev
mailing list