spec/zen/package/users/controller/user_groups.rb in zen-0.3 vs spec/zen/package/users/controller/user_groups.rb in zen-0.4

- old
+ new

@@ -1,83 +1,86 @@ require File.expand_path('../../../../../helper', __FILE__) Zen::Language.load('user_groups') -describe('Users::Controller::UserGroups') do +describe 'Users::Controller::UserGroups' do behaves_like :capybara index_url = Users::Controller::UserGroups.r(:index).to_s save_button = lang('user_groups.buttons.save') new_button = lang('user_groups.buttons.new') delete_button = lang('user_groups.buttons.delete') - it('Submit a form without a CSRF token') do - response = page.driver.post( - Users::Controller::UserGroups.r(:save).to_s - ) - - response.body.include?(lang('zen_general.errors.csrf')).should == true - response.status.should == 403 - end - - it('Find a single user group') do + it 'Find a single user group' do message = lang('user_groups.messages.no_groups') visit(index_url) page.has_content?(message).should == false page.has_selector?('table tbody tr').should == true page.all('table tbody tr').count.should == 1 end - it('Create a new user group') do + it 'Try to create a new user group with a missing CSRF token' do visit(index_url) click_link(new_button) - within('#user_group_form') do + within '#user_group_form' do + find('input[name="csrf_token"]').set('') + click_on(save_button) + end + + page.has_content?(lang('zen_general.errors.csrf')).should == true + end + + it 'Create a new user group' do + visit(index_url) + click_link(new_button) + + within '#user_group_form' do fill_in('name', :with => 'Spec group') choose('form_super_group_0') click_on(save_button) end page.find('input[name="name"]').value.should == 'Spec group' page.find('#form_super_group_0').checked?.should == 'checked' end - it('Search for a user group') do + it 'Search for a user group' do search_button = lang('zen_general.buttons.search') error = lang('zen_general.errors.invalid_search') visit(index_url) - within('#search_form') do + within '#search_form' do fill_in('query', :with => 'Spec group') click_on(search_button) end page.has_content?(error).should == false page.has_content?('Spec group').should == true - within('#search_form') do + within '#search_form' do fill_in('query', :with => 'does not exist') click_on(search_button) end page.has_content?(error).should == false page.has_content?('Spec group').should == false end - it('Edit an existing user group') do + it 'Edit an existing user group' do group = Users::Model::UserGroup[:name => 'Spec group'] path = Users::Controller::UserGroups.r(:edit, group.id).to_s visit(index_url) click_link('Spec group') current_path.should == path - within('#user_group_form') do + within '#user_group_form' do fill_in('name', :with => 'Spec group modified') check('permission_show_user') click_on(save_button) end @@ -86,43 +89,72 @@ page.has_selector?('span.error').should == false page.find('input[name="name"]').value.should == 'Spec group modified' page.find('#permission_show_user').checked?.should == 'checked' end - it('Edit an existing user group with invalid data') do + enable_javascript + + it 'Automatically save a user group' do visit(index_url) + click_link('Spec group modified') + + within '#user_group_form' do + fill_in('name', :with => 'Spec group autosave') + end + + autosave_form('user_group_form') + + visit(index_url) + + page.has_content?('Spec group autosave') + + click_link('Spec group autosave') + + within '#user_group_form' do + fill_in('name', :with => 'Spec group modified') + click_on(save_button) + end + + page.has_selector?('span.error').should == false + page.find('input[name="name"]').value.should == 'Spec group modified' + end + + disable_javascript + + it 'Edit an existing user group with invalid data' do + visit(index_url) click_link('Spec group') - within('#user_group_form') do + within '#user_group_form' do fill_in('name', :with => '') click_on(save_button) end page.has_selector?('label[for="form_name"] span.error').should == true end - it('Delete a group without an ID') do + it 'Delete a group without an ID' do visit(index_url) click_on(delete_button) page.has_selector?('input[name="user_group_ids[]"]').should == true page.all('table tbody tr').count.should == 2 end - it('Delete an existing user group') do + it 'Delete an existing user group' do visit(index_url) - within('table tbody tr:last-child') do + within 'table tbody tr:last-child' do check('user_group_ids[]') end click_on(delete_button) page.all('table tbody tr').count.should == 1 end - it('Call the event new_user_group (before and after)') do + it 'Call the event new_user_group (before and after)' do event_name = nil Zen::Event.listen(:before_new_user_group) do |user_group| user_group.name += ' with event' end @@ -132,11 +164,11 @@ end visit(index_url) click_on(new_button) - within('#user_group_form') do + within '#user_group_form' do fill_in('name', :with => 'Group') choose('form_super_group_0') click_on(save_button) end @@ -145,11 +177,11 @@ event_name.should == 'Group with event' Zen::Event.delete(:before_new_user_group, :after_new_user_group) end - it('Call the event edit_user_group (before and after)') do + it 'Call the event edit_user_group (before and after)' do event_name = nil Zen::Event.listen(:before_edit_user_group) do |user_group| user_group.name = 'Group modified' end @@ -159,22 +191,22 @@ end visit(index_url) click_on('Group with event') - within('#user_group_form') do + within '#user_group_form' do click_on(save_button) end page.has_selector?('span.error').should == false page.find('input[name="name"]').value.should == 'Group modified' event_name.should == 'Group modified' Zen::Event.delete(:before_edit_user_group, :after_edit_user_group) end - it('Call the event delete_user_group (before and after)') do + it 'Call the event delete_user_group (before and after)' do event_name = nil event_name2 = nil Zen::Event.listen(:before_delete_user_group) do |user_group| event_name = user_group.name @@ -184,10 +216,10 @@ event_name2 = user_group.name end visit(index_url) - within('table tbody tr:last-child') do + within 'table tbody tr:last-child' do check('user_group_ids[]') end click_on(delete_button)