+
+ <% button_bar do %>
+ <%= submit_button(:ok, _('Ok!')) %>
+ <% end %>
+<% end %>
diff --git a/features/create_community.feature b/features/create_community.feature
new file mode 100644
index 0000000..66e0674
--- /dev/null
+++ b/features/create_community.feature
@@ -0,0 +1,96 @@
+Feature: create community
+ As a noosfero user
+ I want to create a community
+ In order to interact with other people
+
+ Background:
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+
+ Scenario: a user creates a community
+ Given I am logged in as "joaosilva"
+ And feature "admin_must_approve_new_communities" is disabled on environment
+ And I follow "Control panel"
+ And I follow "Manage my groups"
+ When I follow "Create a new community"
+ And I fill in "Name" with "Fancy community"
+ And I press "Create"
+ Then I should see "Fancy community"
+
+ Scenario: a user creates a community when environment moderates it
+ Given I am logged in as "joaosilva"
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I follow "Control panel"
+ And I follow "Manage my groups"
+ And I follow "Create a new community"
+ And I fill in "Name" with "Community for moderation"
+ And I press "Create"
+ Then I should not see "Community for moderation"
+
+ Scenario: a user tries to create a community without a name
+ Given I am logged in as "joaosilva"
+ And feature "admin_must_approve_new_communities" is disabled on environment
+ And I follow "Control panel"
+ And I follow "Manage my groups"
+ When I follow "Create a new community"
+ And I press "Create"
+ Then I should see "Creating new community"
+
+ Scenario: environment admin receive a task when a user creates a community
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I create community "Community for approval"
+ And I follow "Control Panel"
+ Then I should see "admin_user wants to create community Community for approval"
+
+ Scenario: environment admin accepts new community task
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I create community "Community for approval"
+ And I follow "Control Panel"
+ And I follow "Process requests"
+ And I should see "admin_user wants to create community Community for approval"
+ And I choose "Approve"
+ When I press "Ok!"
+ Then I should not see "admin_user wants to create community Community for approval"
+ When I follow "My groups"
+ Then I should see "Community for approval"
+
+ Scenario: environment admin rejects new community task
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I create community "Community for approval"
+ And I follow "Control Panel"
+ And I follow "Process requests"
+ And I should see "admin_user wants to create community Community for approval"
+ And I choose "Reject"
+ When I press "Ok!"
+ Then I should not see "admin_user wants to create community Community for approval"
+ When I follow "My groups"
+ Then I should not see "Community for approval"
+
+ Scenario: new community is listed after approval
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I create community "Community for approval"
+ And I approve community "Community for approval"
+ When I follow "My groups"
+ Then I should see "Community for approval"
+
+ Scenario: new community is not listed after rejection
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ When I create community "Community for approval"
+ And I reject community "Community for approval"
+ When I follow "My groups"
+ Then I should not see "Community for approval"
+
+ Scenario: environment admin accepts new community task but identifier was already taken
+ Given I am logged in as admin
+ And feature "admin_must_approve_new_communities" is enabled on environment
+ And I create community "Community for approval"
+ And I create community "Community for approval"
+ When I approve community "Community for approval"
+ Then I should see "This name was already taken, this community cannot be approved"
+ And I should see "admin_user wants to create community Community for approval"
diff --git a/features/step_definitions/create_community_steps.rb b/features/step_definitions/create_community_steps.rb
new file mode 100644
index 0000000..8143a51
--- /dev/null
+++ b/features/step_definitions/create_community_steps.rb
@@ -0,0 +1,22 @@
+Given /^I create community "(.+)"$/ do |community|
+ click_link('My groups')
+ click_link('Create a new community')
+ fill_in("Name", :with => community)
+ click_button("Create")
+end
+
+Given /^I approve community "(.+)"$/ do |community|
+ task = CreateCommunity.all.select {|c| c.name == community}.first
+ click_link('Control Panel')
+ click_link('Process requests')
+ choose("decision-finish-#{task.id}")
+ click_button('OK!')
+end
+
+Given /^I reject community "(.+)"$/ do |community|
+ task = CreateCommunity.all.select {|c| c.name == community}.first
+ click_link('Control Panel')
+ click_link('Process requests')
+ choose("decision-cancel-#{task.id}")
+ click_button('OK!')
+end
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index f5ae66b..e04bd89 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -62,7 +62,34 @@ Given /^the following products$/ do |table|
end
Given /^I am logged in as "(.+)"$/ do |username|
+ visit('/account/login')
fill_in("Username", :with => username)
fill_in("Password", :with => '123456')
click_button("Log in")
end
+
+Given /^I am logged in as admin$/ do
+ user = User.create!(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com')
+ e = Environment.default
+ e.add_admin(user.person)
+ visit('/account/login')
+ fill_in("Username", :with => user.login)
+ fill_in("Password", :with => '123456')
+ click_button("Log in")
+end
+
+Given /^I am not logged in$/ do |username|
+ visit('/account/logout')
+end
+
+Given /^feature "(.+)" is enabled on environment$/ do |feature|
+ e = Environment.default
+ e.enable(feature)
+ e.save
+end
+
+Given /^feature "(.+)" is disabled on environment$/ do |feature|
+ e = Environment.default
+ e.disable(feature)
+ e.save
+end
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
index 8efed65..fdb2bb5 100644
--- a/test/fixtures/roles.yml
+++ b/test/fixtures/roles.yml
@@ -73,3 +73,10 @@ environment_administrator:
system: true
permissions:
- perform_task
+ - view_environment_admin_panel
+ - edit_environment_features
+ - edit_environment_design
+ - manage_environment_categories
+ - manage_environment_roles
+ - manage_environment_validators
+ - moderate_comments
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb
index c47d588..ace9ee9 100644
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -649,6 +649,21 @@ class AccountControllerTest < Test::Unit::TestCase
assert_redirected_to :controller => 'home', :action => 'index'
end
+ should 'check_url is available on environment' do
+ env = Environment.create(:name => 'Environment test')
+ @controller.expects(:environment).returns(env).at_least_once
+ profile = create_user('mylogin').person
+ get :check_url, :identifier => 'mylogin'
+ assert_equal 'available', assigns(:status_class)
+ end
+
+ should 'check if url is not available on environment' do
+ @controller.expects(:environment).returns(Environment.default).at_least_once
+ profile = create_user('mylogin').person
+ get :check_url, :identifier => 'mylogin'
+ assert_equal 'unavailable', assigns(:status_class)
+ end
+
protected
def new_user(options = {}, extra_options ={})
data = {:profile_data => person_data}
diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb
index 154abf9..fa5087d 100644
--- a/test/functional/memberships_controller_test.rb
+++ b/test/functional/memberships_controller_test.rb
@@ -220,6 +220,13 @@ class MembershipsControllerTest < Test::Unit::TestCase
get :new_community, :profile => profile.identifier
assert_not_nil assigns(:community).environment
+ end
+
+ should 'set environment' do
+ @controller.stubs(:environment).returns(Environment.default).at_least_once
+ post :new_community, :profile => profile.identifier, :community => {:name => 'test community'}
+
+ assert_not_nil assigns(:community).environment
end
should 'not show description if isnt enabled when register new community' do
diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb
index 6d4fd22..c9bfd52 100644
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -2,6 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper'
class CommunityTest < Test::Unit::TestCase
+ def setup
+ @person = create_user('testuser').person
+ end
+
+ attr_reader :person
+
should 'inherit from Profile' do
assert_kind_of Profile, Community.new
end
@@ -144,5 +150,41 @@ class CommunityTest < Test::Unit::TestCase
assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug)
end
+ should 'sanitize description' do
+ c = Community.create!(:name => 'test_com', :description => 'new community')
+
+ assert_sanitized c.description
+ end
+
+ should 'sanitize name' do
+ c = Community.create!(:name => 'test_com')
+
+ assert_sanitized c.name
+ end
+ should 'create a task when creating a community if feature is enabled' do
+ env = Environment.default
+ env.enable('admin_must_approve_new_communities')
+
+ assert_difference CreateCommunity, :count do
+ Community.create_after_moderation(person, {:environment => env, :name => 'Example'})
+ end
+
+ assert_no_difference Community, :count do
+ Community.create_after_moderation(person, {:environment => env, :name => 'Example'})
+ end
+ end
+
+ should 'create a community if feature is disabled' do
+ env = Environment.default
+ env.disable('admin_must_approve_new_communities')
+
+ assert_difference Community, :count do
+ Community.create_after_moderation(person, {:environment => env, :name => 'Example'})
+ end
+
+ assert_no_difference CreateCommunity, :count do
+ Community.create_after_moderation(person, {:environment => env, :name => 'Example'})
+ end
+ end
end
diff --git a/test/unit/create_community_test.rb b/test/unit/create_community_test.rb
new file mode 100644
index 0000000..c60ed42
--- /dev/null
+++ b/test/unit/create_community_test.rb
@@ -0,0 +1,68 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class CreateCommunityTest < Test::Unit::TestCase
+
+ def setup
+ @person = create_user('testing').person
+ end
+ attr_reader :person
+
+ should 'provide needed data' do
+ task = CreateCommunity.new
+
+ Community.fields + %w[ name closed image_builder tag_list ].each do |field|
+ assert task.respond_to?(field)
+ assert task.respond_to?("#{field}=")
+ end
+ end
+
+ should 'require a requestor' do
+ task = CreateCommunity.new(:name => 'community test', :target => Environment.default)
+ task.valid?
+
+ assert task.errors.invalid?(:requestor_id)
+ task.requestor = person
+ task.valid?
+ assert !task.errors.invalid?(:requestor_id)
+ end
+
+ should 'actually create a community when finishing the task and associate the task requestor as its admin' do
+
+ task = CreateCommunity.create!({
+ :name => 'My new community',
+ :requestor => person,
+ :target => Environment.default,
+ })
+
+ assert_difference Community, :count do
+ task.finish
+ end
+
+ assert_equal person, Community['my-new-community'].admins.first
+ end
+
+ should 'override message methods from Task' do
+ specific = CreateCommunity.new
+ %w[ task_created_message task_finished_message task_cancelled_message ].each do |method|
+ assert_nothing_raised NotImplementedError do
+ specific.send(method)
+ end
+ end
+ end
+
+ should 'provide a message to be sent to the target' do
+ assert_not_nil CreateCommunity.new(:name => 'test comm', :requestor => person).target_notification_message
+ end
+
+ should 'report as approved when approved' do
+ request = CreateCommunity.new
+ request.stubs(:status).returns(Task::Status::FINISHED)
+ assert request.approved?
+ end
+
+ should 'report as rejected when rejected' do
+ request = CreateCommunity.new
+ request.stubs(:status).returns(Task::Status::CANCELLED)
+ assert request.rejected?
+ end
+end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 5f82d00..c48536d 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1462,6 +1462,19 @@ class ProfileTest < Test::Unit::TestCase
assert_equal [event2, event3, event1], profile.events
end
+ should 'be available if identifier doesnt exist on environment' do
+ p = create_user('identifier-test').person
+
+ env = Environment.create(:name => 'Environment test')
+ assert_equal true, Profile.is_available?('identifier-test', env)
+ end
+
+ should 'not be available if identifier exists on environment' do
+ p = create_user('identifier-test').person
+
+ assert_equal false, Profile.is_available?('identifier-test', Environment.default)
+ end
+
private
def assert_invalid_identifier(id)
--
libgit2 0.21.2