Commit 3e98d8f0a6b3dc871c9a663f4919c98b127a1094
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/187' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/187 Conflicts: app/models/environment.rb public/stylesheets/application.css test/factories.rb test/fixtures/roles.yml test/unit/article_test.rb
Showing
33 changed files
with
343 additions
and
7 deletions
Show diff stats
... | ... | @@ -0,0 +1,46 @@ |
1 | +class LicensesController < AdminController | |
2 | + protect 'manage_environment_licenses', :environment | |
3 | + | |
4 | + def index | |
5 | + @licenses = environment.licenses | |
6 | + end | |
7 | + | |
8 | + def create | |
9 | + @license = License.new(params[:license]) | |
10 | + if request.post? | |
11 | + begin | |
12 | + @license.environment = environment | |
13 | + @license.save! | |
14 | + session[:notice] = _('License created') | |
15 | + redirect_to :action => 'index' | |
16 | + rescue | |
17 | + session[:notice] = _('License could not be created') | |
18 | + end | |
19 | + end | |
20 | + end | |
21 | + | |
22 | + def edit | |
23 | + @license = License.find(params[:license_id]) | |
24 | + if request.post? | |
25 | + begin | |
26 | + @license.update_attributes!(params[:license]) | |
27 | + session[:notice] = _('License updated') | |
28 | + redirect_to :action => 'index' | |
29 | + rescue | |
30 | + session[:notice] = _('License could not be updated') | |
31 | + end | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + def remove | |
36 | + @license = License.find(params[:license_id]) | |
37 | + begin | |
38 | + @license.destroy | |
39 | + session[:notice] = _('Licese removed') | |
40 | + rescue | |
41 | + session[:notice] = _('Licese could not be removed') | |
42 | + end | |
43 | + redirect_to :action => 'index' | |
44 | + end | |
45 | + | |
46 | +end | ... | ... |
app/models/article.rb
... | ... | @@ -37,6 +37,8 @@ class Article < ActiveRecord::Base |
37 | 37 | |
38 | 38 | belongs_to :reference_article, :class_name => "Article", :foreign_key => 'reference_article_id' |
39 | 39 | |
40 | + belongs_to :license | |
41 | + | |
40 | 42 | has_many :translations, :class_name => 'Article', :foreign_key => :translation_of_id |
41 | 43 | belongs_to :translation_of, :class_name => 'Article', :foreign_key => :translation_of_id |
42 | 44 | before_destroy :rotate_translations | ... | ... |
app/models/environment.rb
... | ... | @@ -25,6 +25,7 @@ class Environment < ActiveRecord::Base |
25 | 25 | 'manage_environment_validators' => N_('Manage environment validators'), |
26 | 26 | 'manage_environment_users' => N_('Manage environment users'), |
27 | 27 | 'manage_environment_templates' => N_('Manage environment templates'), |
28 | + 'manage_environment_licenses' => N_('Manage environment licenses'), | |
28 | 29 | } |
29 | 30 | |
30 | 31 | module Roles |
... | ... | @@ -159,6 +160,7 @@ class Environment < ActiveRecord::Base |
159 | 160 | has_many :products, :through => :enterprises |
160 | 161 | has_many :people |
161 | 162 | has_many :communities |
163 | + has_many :licenses | |
162 | 164 | |
163 | 165 | has_many :categories |
164 | 166 | has_many :display_categories, :class_name => 'Category', :conditions => 'display_color is not null and parent_id is null', :order => 'display_color' |
... | ... | @@ -741,6 +743,18 @@ class Environment < ActiveRecord::Base |
741 | 743 | end |
742 | 744 | end |
743 | 745 | |
746 | + after_create :create_default_licenses | |
747 | + def create_default_licenses | |
748 | + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => self) | |
749 | + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => self) | |
750 | + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => self) | |
751 | + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => self) | |
752 | + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => self) | |
753 | + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => self) | |
754 | + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => self) | |
755 | + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => self) | |
756 | + end | |
757 | + | |
744 | 758 | def highlighted_products_with_image(options = {}) |
745 | 759 | Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) |
746 | 760 | end | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +class License < ActiveRecord::Base | |
2 | + belongs_to :environment | |
3 | + has_many :content, :class_name => 'Article', :foreign_key => 'license_id' | |
4 | + | |
5 | + validates_presence_of :name, :environment | |
6 | + validates_presence_of :slug, :if => lambda {|license| license.name.present?} | |
7 | + validates_uniqueness_of :slug, :scope => :environment_id | |
8 | + | |
9 | + before_validation do |license| | |
10 | + license.slug ||= license.name.to_slug if license.name.present? | |
11 | + end | |
12 | +end | ... | ... |
app/views/admin_panel/index.rhtml
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | <tr><td><%= link_to _('Edit Templates'), :controller => 'templates' %></td></tr> |
16 | 16 | <tr><td><%= link_to _('Manage Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr> |
17 | 17 | <tr><td><%= link_to _('Set Portal'), :action => 'set_portal_community' %></td></tr> |
18 | + <tr><td><%= link_to _('Manage Licenses'), :controller =>'licenses' %></td></tr> | |
18 | 19 | <% @plugins.dispatch(:admin_panel_links).each do |link| %> |
19 | 20 | <tr><td><%= link_to link[:title], link[:url] %></td></tr> |
20 | 21 | <% end %> | ... | ... |
app/views/cms/_blog.rhtml
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | |
7 | 7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> |
8 | 8 | |
9 | +<%= render :partial => 'general_fields' %> | |
10 | + | |
9 | 11 | <script type="text/javascript"> |
10 | 12 | function submit_button(index) { |
11 | 13 | return $("article_slug").form.select("input.submit")[index]; | ... | ... |
app/views/cms/_event.rhtml
app/views/cms/_folder.rhtml
app/views/cms/_forum.rhtml
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | |
7 | 7 | <%= required f.text_field(:name, :size => '64', :onchange => "updateUrlField(this, 'article_slug')") %> |
8 | 8 | |
9 | +<%= render :partial => 'general_fields' %> | |
10 | + | |
9 | 11 | <%= labelled_form_field(_('Description:'), text_area(:article, :body, :cols => 64, :rows => 10)) %> |
10 | 12 | |
11 | 13 | <%= labelled_form_field(_('Posts per page:'), f.select(:posts_per_page, [5, 10, 20, 50, 100])) %> | ... | ... |
app/views/cms/_gallery.rhtml
... | ... | @@ -0,0 +1 @@ |
1 | +<%= labelled_form_field(_('License'), select(:article, :license_id, [[_('None'), nil]] + profile.environment.licenses.map {|license| [license.name, license.id]})) %> | ... | ... |
app/views/cms/_published_article.rhtml
app/views/cms/_raw_html_article.rhtml
app/views/cms/_rss_feed.rhtml
... | ... | @@ -2,6 +2,8 @@ |
2 | 2 | |
3 | 3 | <%= required f.text_field(:name) %> |
4 | 4 | |
5 | +<%= render :partial => 'general_fields' %> | |
6 | + | |
5 | 7 | <%= required labelled_form_field(_('Limit of articles'), text_field(:article, :limit)) %> |
6 | 8 | |
7 | 9 | <%= labelled_form_field(_('Include in RSS Feed only posts from language:'), f.select(:language, [[_('All'), nil ]] + Noosfero.locales.map { |k,v| [v, k]})) %> | ... | ... |
app/views/cms/_textile_article.rhtml
app/views/cms/_tiny_mce_article.rhtml
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | <div> |
6 | 6 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64')) %> |
7 | 7 | |
8 | + <%= render :partial => 'general_fields' %> | |
8 | 9 | <%= render :partial => 'translatable' %> |
9 | 10 | <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true} %> |
10 | 11 | </div> | ... | ... |
app/views/content_viewer/view_page.rhtml
... | ... | @@ -12,6 +12,22 @@ |
12 | 12 | <%= remote_function :update => "article-toolbar", :url => @page.url.merge({ :toolbar => true, :only_path => true }) %> |
13 | 13 | </script> |
14 | 14 | |
15 | +<% if @page.display_hits? || @page.license.present? %> | |
16 | + <div id='article-sub-header'> | |
17 | + <% if @page.display_hits? %> | |
18 | + <div id="article-hits"> | |
19 | + <%= n_('Viewed one time', 'Viewed %{num} times', @page.hits) % { :num => @page.hits } %> | |
20 | + </div> | |
21 | + <% end %> | |
22 | + | |
23 | + <% if @page.license.present? %> | |
24 | + <div id="article-license"> | |
25 | + <%= _('Licensed under %s') % (@page.license.url.present? ? link_to(@page.license.name, @page.license.url, :target => '_blank') : @page.license.name) %> | |
26 | + </div> | |
27 | + <% end %> | |
28 | + </div> | |
29 | +<% end %> | |
30 | + | |
15 | 31 | <% if !@page.tags.empty? %> |
16 | 32 | <div id="article-tags"> |
17 | 33 | <%= _("This article's tags:") %> |
... | ... | @@ -19,12 +35,6 @@ |
19 | 35 | </div> |
20 | 36 | <% end %> |
21 | 37 | |
22 | -<% if @page.display_hits? %> | |
23 | - <div id="article-hits"> | |
24 | - <%= n_('Viewed one time', 'Viewed %{num} times', @page.hits) % { :num => @page.hits } %> | |
25 | - </div> | |
26 | -<% end %> | |
27 | - | |
28 | 38 | <% if @page.parent && !@page.parent.path.blank? %> |
29 | 39 | <div id="article-parent"> |
30 | 40 | <%= button(:back, _('Go back to %s') % @page.parent.short_title, @page.parent.url) %> | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +<%= error_messages_for :license %> | |
2 | + | |
3 | +<% form_for :license, @license do |f| %> | |
4 | + <%= hidden_field_tag(:license_id, params[:license_id]) %> | |
5 | + <%= required labelled_form_field(_('Name'), f.text_field(:name)) %> | |
6 | + <%= labelled_form_field(_('License url'), f.text_field(:url)) %> | |
7 | + | |
8 | + <% button_bar do %> | |
9 | + <%= submit_button('save', _('Save'))%> | |
10 | + <%= button('cancel', _('Cancel'), {:action => 'index'})%> | |
11 | + <% end %> | |
12 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +<h1><%= _('Manage licenses') %></h1> | |
2 | +<table style='width: 100%; overflow: hidden;'> | |
3 | + <tr> | |
4 | + <th style='width: 25%'><%= _('Name') %></th> | |
5 | + <th style='width: 60%'><%= _('Url reference') %></th> | |
6 | + <th style='width: 15%'><%= _('Actions') %></th> | |
7 | + </tr> | |
8 | + <% @licenses.each do |license| %> | |
9 | + <tr> | |
10 | + <td title="<%= license.name%>"><%= truncate(license.name, 19) %></td> | |
11 | + <td title="<%= license.url %>"><%= license.url.present? ? link_to(truncate(license.url, 60), license.url, :target => '_blank') : '' %></td> | |
12 | + <td style='white-space: nowrap;'> | |
13 | + <%= button_without_text :edit, _('Edit'), :action => 'edit', :license_id => license.id %> | |
14 | + <%= button_without_text :remove, _('Remove'), {:action => 'remove', :license_id => license.id}, :confirm => _('Are you sure you want to remove this license?') %></td> | |
15 | + </tr> | |
16 | + <% end %> | |
17 | + <tr> | |
18 | + <td colspan='3' style='text-align: center'><strong><%= link_to(_('NEW LICENSE'), :action => 'create')%></strong></td> | |
19 | + </tr> | |
20 | +</table> | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +class CreateLicenses < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + create_table :licenses do |t| | |
4 | + t.string :name, :null => false | |
5 | + t.string :slug, :null => false | |
6 | + t.string :url | |
7 | + t.references :environment, :null => false | |
8 | + end | |
9 | + end | |
10 | + | |
11 | + def self.down | |
12 | + drop_table :licenses | |
13 | + end | |
14 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +class AddLicenseToArticle < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + add_column :articles, :license_id, :integer | |
4 | + add_column :article_versions, :license_id, :integer | |
5 | + end | |
6 | + | |
7 | + def self.down | |
8 | + remove_column :articles, :license_id | |
9 | + remove_column :article_versions, :license_id | |
10 | + end | |
11 | +end | ... | ... |
db/migrate/20120716161506_add_manage_environment_license_to_admin_role.rb
0 → 100644
... | ... | @@ -0,0 +1,17 @@ |
1 | +class AddManageEnvironmentLicenseToAdminRole < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + Environment.all.map(&:id).each do |id| | |
4 | + role = Environment::Roles.admin(id) | |
5 | + role.permissions << 'manage_environment_licenses' | |
6 | + role.save! | |
7 | + end | |
8 | + end | |
9 | + | |
10 | + def self.down | |
11 | + Environment.all.map(&:id).each do |id| | |
12 | + role = Environment::Roles.admin(id) | |
13 | + role.permissions -= ['manage_environment_licenses'] | |
14 | + role.save! | |
15 | + end | |
16 | + end | |
17 | +end | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +class CreateDefaultLicenses < ActiveRecord::Migration | |
2 | + def self.up | |
3 | + Environment.all.each do |environment| | |
4 | + License.create!(:name => 'CC (by)', :url => 'http://creativecommons.org/licenses/by/3.0/legalcode', :environment => environment) | |
5 | + License.create!(:name => 'CC (by-nd)', :url => 'http://creativecommons.org/licenses/by-nd/3.0/legalcode', :environment => environment) | |
6 | + License.create!(:name => 'CC (by-sa)', :url => 'http://creativecommons.org/licenses/by-sa/3.0/legalcode', :environment => environment) | |
7 | + License.create!(:name => 'CC (by-nc)', :url => 'http://creativecommons.org/licenses/by-nc/3.0/legalcode', :environment => environment) | |
8 | + License.create!(:name => 'CC (by-nc-nd)', :url => 'http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode', :environment => environment) | |
9 | + License.create!(:name => 'CC (by-nc-sa)', :url => 'http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode', :environment => environment) | |
10 | + License.create!(:name => 'Free Art', :url => 'http://artlibre.org/licence/lal/en', :environment => environment) | |
11 | + License.create!(:name => 'GNU FDL', :url => 'http://www.gnu.org/licenses/fdl-1.3.txt', :environment => environment) | |
12 | + end | |
13 | + end | |
14 | + | |
15 | + def self.down | |
16 | + licenses = [] | |
17 | + licenses += License.find(:all, :conditions => {:name => 'CC (by)'}) | |
18 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nd)'}) | |
19 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-sa)'}) | |
20 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc)'}) | |
21 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-nd)'}) | |
22 | + licenses += License.find(:all, :conditions => {:name => 'CC (by-nc-sa)'}) | |
23 | + licenses += License.find(:all, :conditions => {:name => 'Free Art'}) | |
24 | + licenses += License.find(:all, :conditions => {:name => 'GNU FDL'}) | |
25 | + licenses.compact.map(&:destroy) | |
26 | + end | |
27 | +end | ... | ... |
public/stylesheets/application.css
... | ... | @@ -892,13 +892,26 @@ code input { |
892 | 892 | #article-tags { |
893 | 893 | font-size: 10px; |
894 | 894 | text-align: right; |
895 | + margin-bottom: -10px; | |
895 | 896 | } |
896 | 897 | #article-tags a { |
897 | 898 | text-decoration: none; |
898 | 899 | } |
900 | + | |
901 | +#article-sub-header { | |
902 | + height: 15px; | |
903 | +} | |
904 | + | |
899 | 905 | #article-hits { |
900 | 906 | font-size: 10px; |
907 | + float: left; | |
908 | +} | |
909 | + | |
910 | +#article-license { | |
911 | + font-size: 10px; | |
912 | + float: right; | |
901 | 913 | text-align: right; |
914 | + color: #AAA; | |
902 | 915 | } |
903 | 916 | #article-cat { |
904 | 917 | font-size: 10px; | ... | ... |
test/factories.rb
... | ... | @@ -58,7 +58,7 @@ module Noosfero::Factory |
58 | 58 | ###### old stuff to be rearranged |
59 | 59 | def create_admin_user(env) |
60 | 60 | admin_user = User.find_by_login('adminuser') || create_user('adminuser', :email => 'adminuser@noosfero.org', :password => 'adminuser', :password_confirmation => 'adminuser', :environment => env) |
61 | - admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates']) | |
61 | + admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators', 'manage_environment_users', 'manage_environment_templates', 'manage_environment_licenses']) | |
62 | 62 | RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) |
63 | 63 | admin_user.login |
64 | 64 | end | ... | ... |
test/fixtures/roles.yml
... | ... | @@ -35,6 +35,7 @@ four: |
35 | 35 | - perform_task |
36 | 36 | - manage_environment_users |
37 | 37 | - manage_environment_templates |
38 | + - manage_environment_licenses | |
38 | 39 | profile_admin: |
39 | 40 | id: 5 |
40 | 41 | environment_id: 1 |
... | ... | @@ -88,3 +89,4 @@ environment_administrator: |
88 | 89 | - edit_profile |
89 | 90 | - destroy_profile |
90 | 91 | - manage_environment_templates |
92 | + - manage_environment_licenses | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -1545,6 +1545,17 @@ class CmsControllerTest < ActionController::TestCase |
1545 | 1545 | assert_includes special_article_types, Float |
1546 | 1546 | end |
1547 | 1547 | |
1548 | + should 'be able to define license when updating article' do | |
1549 | + article = fast_create(Article, :profile_id => profile.id) | |
1550 | + license = License.create!(:name => 'GPLv3', :environment => profile.environment) | |
1551 | + login_as(profile.identifier) | |
1552 | + | |
1553 | + post :edit, :profile => profile.identifier, :id => article.id, :article => { :license_id => license.id } | |
1554 | + | |
1555 | + article.reload | |
1556 | + assert_equal license, article.license | |
1557 | + end | |
1558 | + | |
1548 | 1559 | protected |
1549 | 1560 | |
1550 | 1561 | # FIXME this is to avoid adding an extra dependency for a proper JSON parser. | ... | ... |
... | ... | @@ -0,0 +1,46 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'licenses_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class LIcensesController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class LicensesControllerTest < ActionController::TestCase | |
8 | + | |
9 | + def setup | |
10 | + @controller = LicensesController.new | |
11 | + @request = ActionController::TestRequest.new | |
12 | + @response = ActionController::TestResponse.new | |
13 | + @environment = Environment.default | |
14 | + login_as(create_admin_user(@environment)) | |
15 | + end | |
16 | + | |
17 | + attr_accessor :environment | |
18 | + | |
19 | + should 'list environment licenses' do | |
20 | + l1 = License.create!(:name => 'GPLv3', :environment => environment) | |
21 | + l2 = License.create!(:name => 'AGPL', :environment => environment) | |
22 | + | |
23 | + get :index | |
24 | + | |
25 | + assert_includes assigns(:licenses), l1 | |
26 | + assert_includes assigns(:licenses), l2 | |
27 | + end | |
28 | + | |
29 | + should 'create a new license' do | |
30 | + assert_difference License, :count, 1 do | |
31 | + post :create, :license => {:name => 'GPLv3'} | |
32 | + end | |
33 | + end | |
34 | + | |
35 | + should 'edit a license' do | |
36 | + license = License.create!(:name => 'GPLv2', :environment => environment) | |
37 | + post :edit, :license_id => license.id, :license => {:name => 'GPLv3'} | |
38 | + assert_equal 'GPLv3', License.last.name | |
39 | + end | |
40 | + | |
41 | + should 'remove a license' do | |
42 | + license = License.create!(:name => 'GPLv3', :environment => environment) | |
43 | + post :remove, :license_id => license.id | |
44 | + assert_raise(ActiveRecord::RecordNotFound) {License.find(license.id)} | |
45 | + end | |
46 | +end | ... | ... |
test/unit/article_test.rb
... | ... | @@ -1725,4 +1725,11 @@ class ArticleTest < ActiveSupport::TestCase |
1725 | 1725 | a = TinyMceArticle.create! :name => 'Tracked Article', :body => '<p>Foo<img src="foo.png" />Bar</p>', :profile_id => profile.id |
1726 | 1726 | assert_equal 'foo.png', ActionTracker::Record.last.get_first_image |
1727 | 1727 | end |
1728 | + | |
1729 | + should 'be able to have a license' do | |
1730 | + license = License.create!(:name => 'GPLv3', :environment => Environment.default) | |
1731 | + article = Article.new(:license_id => license.id) | |
1732 | + assert_equal license, article.license | |
1733 | + end | |
1734 | + | |
1728 | 1735 | end | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -1206,4 +1206,18 @@ class EnvironmentTest < ActiveSupport::TestCase |
1206 | 1206 | should 'have production costs' do |
1207 | 1207 | assert_respond_to Environment.default, :production_costs |
1208 | 1208 | end |
1209 | + | |
1210 | + should 'be able to have many licenses' do | |
1211 | + environment = Environment.default | |
1212 | + another_environment = fast_create(Environment) | |
1213 | + l1 = License.create!(:name => 'GPLv3', :environment => environment) | |
1214 | + l2 = License.create!(:name => 'AGPL', :environment => environment) | |
1215 | + l3 = License.create!(:name => 'Apache', :environment => another_environment) | |
1216 | + | |
1217 | + environment.reload | |
1218 | + | |
1219 | + assert_includes environment.licenses, l1 | |
1220 | + assert_includes environment.licenses, l2 | |
1221 | + assert_not_includes environment.licenses, l3 | |
1222 | + end | |
1209 | 1223 | end | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class LicenseTest < ActiveSupport::TestCase | |
4 | + should 'validate presence of name and environment' do | |
5 | + license = License.new | |
6 | + license.valid? | |
7 | + assert license.errors.invalid?(:name) | |
8 | + assert license.errors.invalid?(:environment) | |
9 | + | |
10 | + license.name = 'GPLv3' | |
11 | + license.environment = Environment.default | |
12 | + license.valid? | |
13 | + assert !license.errors.invalid?(:name) | |
14 | + assert !license.errors.invalid?(:environment) | |
15 | + end | |
16 | + | |
17 | + should 'fill in slug before creation' do | |
18 | + license = License.new(:name => 'GPLv3', :environment => Environment.default) | |
19 | + assert license.valid? | |
20 | + assert_equal license.name.to_slug, license.slug | |
21 | + end | |
22 | + | |
23 | + should 'not overwrite slug if it is already fill' do | |
24 | + license = License.new(:name => 'GPLv3', :slug => 'some-slug', :environment => Environment.default) | |
25 | + license.valid? | |
26 | + assert_equal 'some-slug', license.slug | |
27 | + end | |
28 | + | |
29 | + should 'allow equal slugs in different environments' do | |
30 | + e1 = fast_create(Environment) | |
31 | + e2 = fast_create(Environment) | |
32 | + License.create!(:name => 'License', :environment => e1) | |
33 | + license = License.new(:name => 'License', :environment => e2) | |
34 | + | |
35 | + assert license.valid? | |
36 | + end | |
37 | +end | |
38 | + | ... | ... |