Commit dd8aaa4737740b49f8450ca2f3e9255a9b351ad7

Authored by Leandro Santos
2 parents fe6c058f 7018c3d2

Merge branch 'hide_license' into 'master'

Hide license

Hide license selection when there is no license available on environment

See merge request !438
app/models/environment.rb
... ... @@ -937,6 +937,10 @@ class Environment < ActiveRecord::Base
937 937 locales_list
938 938 end
939 939  
  940 + def has_license?
  941 + self.licenses.any?
  942 + end
  943 +
940 944 private
941 945  
942 946 def default_language_available
... ...
app/views/cms/_general_fields.html.erb
1 1 <%= select_profile_folder(_('Parent folder:'), 'article[parent_id]', profile, @article.parent_id) %>
2   -<%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %>
  2 +<% if profile.environment.has_license? %>
  3 + <%= labelled_form_field(_('License'), select(:article, :license_id, options_for_select_with_title([[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]}, @article.license ? @article.license.id : nil))) %>
  4 +<% end %>
... ...
test/functional/cms_controller_test.rb
... ... @@ -1678,6 +1678,15 @@ class CmsControllerTest &lt; ActionController::TestCase
1678 1678 assert_equal license, article.license
1679 1679 end
1680 1680  
  1681 + should 'not display license field if there is no license availabe in environment' do
  1682 + article = fast_create(Article, :profile_id => profile.id)
  1683 + License.delete_all
  1684 + login_as(profile.identifier)
  1685 +
  1686 + get :new, :profile => profile.identifier, :type => 'TinyMceArticle'
  1687 + assert_no_tag :tag => 'select', :attributes => {:id => 'article_license_id'}
  1688 + end
  1689 +
1681 1690 should 'list folders options to move content' do
1682 1691 article = fast_create(Article, :profile_id => profile.id)
1683 1692 f1 = fast_create(Folder, :profile_id => profile.id)
... ...
test/unit/environment_test.rb
... ... @@ -1627,4 +1627,26 @@ class EnvironmentTest &lt; ActiveSupport::TestCase
1627 1627  
1628 1628 assert_equal 'Welcome to the environment', environment.signup_welcome_screen_body
1629 1629 end
  1630 +
  1631 + should 'has_license be true if there is one license in enviroment' do
  1632 + e = fast_create(Environment)
  1633 + fast_create(License, :name => 'Some', :environment_id => e.id)
  1634 +
  1635 + assert e.has_license?
  1636 + end
  1637 +
  1638 + should 'has_license be true if there is many licenses in enviroment' do
  1639 + e = fast_create(Environment)
  1640 + fast_create(License, :name => 'Some', :environment_id => e.id)
  1641 + fast_create(License, :name => 'Another', :environment_id => e.id)
  1642 +
  1643 + assert e.has_license?
  1644 + end
  1645 +
  1646 + should 'has_license be false if there is no license in enviroment' do
  1647 + e = fast_create(Environment)
  1648 +
  1649 + assert !e.has_license?
  1650 + end
  1651 +
1630 1652 end
... ...