Commit 334cbb56f5d2e670504afc7baf96b58fa9f47730

Authored by Leandro Santos
2 parents 83eb7307 688cc083
Exists in staging and in 1 other branch production

Merge branch 'master' into staging

app/api/helpers.rb
... ... @@ -451,9 +451,11 @@ module Api
451 451  
452 452 def parse_content_type(content_type)
453 453 return nil if content_type.blank?
454   - content_type.split(',').map do |content_type|
455   - content_type.camelcase
  454 + content_types = content_type.split(',').map do |content_type|
  455 + content_type = content_type.camelcase
  456 + content_type == 'TextArticle' ? Article.text_article_types : content_type
456 457 end
  458 + content_types.flatten.uniq
457 459 end
458 460  
459 461 def period(from_date, until_date)
... ...
app/views/cms/_text_fields.html.erb
1   -<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, {:max_date => '+0d', :date_format => 'yy-mm-dd'}, {:id => "article_published_at"})) %>
  1 +<%= labelled_form_field(_('Publish date'), date_field('article[published_at]', @article.published_at || DateTime.current, {:max_date => '+0d', :time => true}, {:id => "article_published_at"})) %>
... ...
features/edit_article.feature
... ... @@ -281,3 +281,16 @@ Feature: edit article
281 281 And I press "Save"
282 282 Then I should not see "Language must be choosen"
283 283 And I should be on /joaosilva/article-in-portuguese
  284 +
  285 + @selenium
  286 + Scenario: create an article with time
  287 + Given I am on joaosilva's control panel
  288 + And I follow "Manage Content"
  289 + And I follow "New content"
  290 + When I follow "Text article with visual editor"
  291 + And I fill in "Title" with "My time testing Article"
  292 + And I fill in "Publish date" with "1980-11-15 20:37"
  293 + And I press "Save"
  294 + And I go to /joaosilva/my-time-testing-article
  295 + Then I should see "November 15, 1980 20:37"
  296 +
... ...
plugins/organization_ratings/db/migrate/20160523193515_add_initial_page_to_organization_ratings_config.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class AddInitialPageToOrganizationRatingsConfig < ActiveRecord::Migration
  2 + def up
  3 + add_column :organization_ratings_configs, :ratings_on_initial_page, :integer, :default => 3
  4 + end
  5 +
  6 + def down
  7 + remove_column :organization_ratings_configs, :ratings_on_initial_page
  8 + end
  9 +end
... ...
plugins/organization_ratings/lib/organization_ratings_block.rb
... ... @@ -13,6 +13,10 @@ class OrganizationRatingsBlock &lt; Block
13 13 env_organization_ratings_config.per_page
14 14 end
15 15  
  16 + def ratings_on_initial_page
  17 + env_organization_ratings_config.ratings_on_initial_page
  18 + end
  19 +
16 20 def cacheable?
17 21 false
18 22 end
... ...
plugins/organization_ratings/lib/organization_ratings_config.rb
... ... @@ -4,6 +4,7 @@ class OrganizationRatingsConfig &lt; ApplicationRecord
4 4  
5 5 attr_accessible :cooldown, :default_rating, :order, :per_page
6 6 attr_accessible :vote_once, :are_moderated, :environment_id
  7 + attr_accessible :ratings_on_initial_page
7 8  
8 9 ORDER_OPTIONS = {recent: _('More Recent'), best: _('Best Ratings')}
9 10  
... ...
plugins/organization_ratings/test/unit/organization_rating_config_test.rb
... ... @@ -29,15 +29,29 @@ class OrganizationRatingConfigTest &lt; ActiveSupport::TestCase
29 29 assert_equal "must be greater than or equal to 0", @organization_ratings_config.errors[:cooldown].first
30 30 end
31 31  
32   - # test "communities ratings per page validation" do
33   - # environment = Environment.new :communities_ratings_per_page => 4
34   - # environment.valid?
  32 + test "communities ratings per page validation" do
  33 + @organization_ratings_config.per_page = 4
35 34  
36   - # assert_equal "must be greater than or equal to 5", environment.errors[:communities_ratings_per_page].first
  35 + refute @organization_ratings_config.valid?
37 36  
38   - # environment.communities_ratings_per_page = 21
39   - # environment.valid?
  37 + assert_equal "must be greater than or equal to 5", @organization_ratings_config.errors[:per_page].first
40 38  
41   - # assert_equal "must be less than or equal to 20", environment.errors[:communities_ratings_per_page].first
42   - # end
  39 + @organization_ratings_config.per_page = 21
  40 + refute @organization_ratings_config.valid?
  41 +
  42 + assert_equal "must be less than or equal to 20", @organization_ratings_config.errors[:per_page].first
  43 + end
  44 +
  45 + should "ratings block use initial_page config" do
  46 + @organization_ratings_config.ratings_on_initial_page = 4
  47 + @organization_ratings_config.save!
  48 + block = OrganizationRatingsBlock.new
  49 + assert_equal block.ratings_on_initial_page, 4
  50 + end
  51 +
  52 + should "ratings block show 3 ratings on initial page by default" do
  53 + @organization_ratings_config.save!
  54 + block = OrganizationRatingsBlock.new
  55 + assert_equal block.ratings_on_initial_page, 3
  56 + end
43 57 end
... ...
plugins/organization_ratings/views/blocks/organization_ratings.html.erb
... ... @@ -7,7 +7,7 @@
7 7 <% else %>
8 8 <div class="ratings-list">
9 9 <% block.get_ratings(block.owner.id).each_with_index do |r, index| %>
10   - <% break if index >= block.limit_number_of_ratings %>
  10 + <% break if index >= block.ratings_on_initial_page %>
11 11 <%= render :partial => "shared/user_rating_container", :locals => {:user_rate => r} %>
12 12 <% end %>
13 13  
... ...
plugins/organization_ratings/views/organization_ratings_plugin_admin/index.html.erb
... ... @@ -43,6 +43,12 @@
43 43 <%= c.select :per_page, 5..20 %>
44 44 </td>
45 45 </tr>
  46 + <tr>
  47 + <td><%= _('Ratings amount on initial page') %></td>
  48 + <td>
  49 + <%= c.select :ratings_on_initial_page, 1..10 %>
  50 + </td>
  51 + </tr>
46 52 </table>
47 53 <div>
48 54 <%= button_bar do %>
... ...
test/api/articles_test.rb
... ... @@ -34,6 +34,17 @@ class ArticlesTest &lt; ActiveSupport::TestCase
34 34 assert_includes json["articles"].map { |a| a["id"] }, article.id
35 35 end
36 36  
  37 + should 'list all text articles' do
  38 + profile = Community.create(identifier: 'my-community', name: 'name-my-community')
  39 + a1 = fast_create(TextArticle, :profile_id => profile.id)
  40 + a2 = fast_create(TextileArticle, :profile_id => profile.id)
  41 + a3 = fast_create(TinyMceArticle, :profile_id => profile.id)
  42 + params['content_type']='TextArticle'
  43 + get "api/v1/communities/#{profile.id}/articles?#{params.to_query}"
  44 + json = JSON.parse(last_response.body)
  45 + assert_equal 3, json['articles'].count
  46 + end
  47 +
37 48 should 'get profile homepage' do
38 49 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
39 50 person.home_page=article
... ... @@ -125,6 +136,17 @@ class ArticlesTest &lt; ActiveSupport::TestCase
125 136 assert_equivalent [child1.id, child2.id], json["articles"].map { |a| a["id"] }
126 137 end
127 138  
  139 + should 'list all text articles of children' do
  140 + article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
  141 + child1 = fast_create(TextArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 1")
  142 + child2 = fast_create(TextileArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 2")
  143 + child3 = fast_create(TinyMceArticle, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing 3")
  144 + get "/api/v1/articles/#{article.id}/children?#{params.to_query}"
  145 + json = JSON.parse(last_response.body)
  146 + assert_equivalent [child1.id, child2.id, child3.id], json["articles"].map { |a| a["id"] }
  147 + end
  148 +
  149 +
128 150 should 'list public article children for not logged in access' do
129 151 article = fast_create(Article, :profile_id => user.person.id, :name => "Some thing")
130 152 child1 = fast_create(Article, :parent_id => article.id, :profile_id => user.person.id, :name => "Some thing")
... ...
test/api/helpers_test.rb
... ... @@ -99,7 +99,7 @@ class Api::HelpersTest &lt; ActiveSupport::TestCase
99 99 end
100 100  
101 101 should 'parse_content_type return all content types as an array' do
102   - assert_equivalent ['TextArticle','TinyMceArticle'], parse_content_type("TextArticle,TinyMceArticle")
  102 + assert_equivalent ['TextileArticle','TinyMceArticle'], parse_content_type("TextileArticle,TinyMceArticle")
103 103 end
104 104  
105 105 should 'find_article return article by id in list passed for user with permission' do
... ...