fix #1042 and create test for it

This commit is contained in:
Reinier Balt 2010-08-03 20:55:07 +02:00
parent a9726766b3
commit 6be18a104b
6 changed files with 72 additions and 37 deletions

View file

@ -105,7 +105,6 @@ class ProjectsController < ApplicationController
if params['project']['state']
@new_state = params['project']['state']
@state_changed = @project.state != @new_state
logger.info "@state_changed: #{@project.state} == #{params['project']['state']} != #{@state_changed}"
params['project'].delete('state')
end
success_text = if params['field'] == 'name' && params['value']
@ -113,7 +112,8 @@ class ProjectsController < ApplicationController
params['project']['name'] = params['value']
end
@project.attributes = params['project']
if @project.save
@saved = @project.save
if @saved
@project.transition_to(@new_state) if @state_changed
if boolean_param('wants_render')
if (@project.hidden?)
@ -149,8 +149,8 @@ class ProjectsController < ApplicationController
return
end
else
notify :warning, "Couldn't update project"
render :text => ''
init_data_for_sidebar
render :template => 'projects/update.js.rjs'
return
end
render :template => 'projects/update.js.rjs'

View file

@ -3,7 +3,7 @@ project = project_form
%>
<% form_remote_tag(:url => project_path(project), :html => { :id => dom_id(project, 'edit_form'), :class => "inline-form "+dom_id(project, 'edit_form')+"-edit-project-form", :method => :put }) do -%>
<div id="error_status"><%= error_messages_for("project") %></div>
<%= source_view_tag( @source_view ) -%>
<label for="project_name">Name:</label><br/>

View file

@ -27,7 +27,8 @@ suppress_edit_button ||= false
:method => 'get',
:with => "'_source_view=#{@source_view}'",
:before => "$('#{dom_id(project)}').block({message:null});",
:complete => "$('#{dom_id(project)}').unblock();enable_rich_interaction();"
:complete => "$('#{dom_id(project)}').unblock();enable_rich_interaction();",
:html => {:id => "link_edit_#{dom_id(project)}"}
) %>
<% end -%>

View file

@ -1,6 +1,7 @@
status_message = 'Project saved'
page.notify :notice, status_message, 5.0
if source_view_is :project_list
if @saved
status_message = 'Project saved'
page.notify :notice, status_message, 5.0
if source_view_is :project_list
if @state_changed
page[dom_id(@project, 'container')].remove
page.insert_html :bottom, "list-#{@project.state}-projects", :partial => 'project_listing', :object => @project
@ -15,7 +16,7 @@ if source_view_is :project_list
page.set_element_visible("list-hidden-projects-container", @hidden_projects_count > 0)
page.set_element_visible("list-active-projects-container", @active_projects_count > 0)
page.set_element_visible("list-completed-projects-container", @completed_projects_count > 0)
else
else
page[dom_id(@project, 'edit')].hide
page.replace_html dom_id(@project, 'container'), :partial => 'project_settings', :locals => { :project => @project }
page[dom_id(@project)].show
@ -24,11 +25,15 @@ else
page['#todo_project_name'].value = @project.name
page['tag_list'].value = @project.default_tags if @project.default_tags
page << "$('input[name=default_context_name]').val('#{@project.default_context.name}');" if @project.default_context
end
page['default_project_name_id'].value = @project.name
page['todo_project_name'].value = @project.name
page.replace_html "project_name", @project.name
page.replace_html "sidebar", :file => 'sidebar/sidebar.html.erb'
else
page.show 'error_status'
page.replace_html 'error_status', "#{error_messages_for('project')}"
end
page['default_project_name_id'].value = @project.name
page['todo_project_name'].value = @project.name
page.replace_html "project_name", @project.name
page.replace_html "sidebar", :file => 'sidebar/sidebar.html.erb'
page << "enable_rich_interaction();"

View file

@ -34,3 +34,22 @@ Feature: Manage a project
When I visit the "bananas" project
And I edit the project name to "cherries"
Then the project title should be "cherries"
# Ticket #1042
@selenium
Scenario: I cannot change the name of a project in the project view to the name of another existing project
Given I have a project "test" with 1 todos
When I go to the projects page
Then the badge should show 2 # "manage me" and "test"
When I visit the "manage me" project
And I edit the project name to "test"
Then I should see "Name already exists"
# Ticket #1042
@selenium
Scenario: I cannot change the name of a project in the project list view to the name of another existing project
Given I have a project "test" with 1 todos
When I go to the projects page
Then the badge should show 2 # "manage me" and "test"
When I edit the project name of "manage me" to "test"
Then I should see "Name already exists"

View file

@ -43,10 +43,20 @@ end
When /^I edit the project name to "([^\"]*)"$/ do |new_title|
click_link "link_edit_project_#{@project.id}"
fill_in "project[name]", :with => new_title
# changed to make sure selenium waits until the saving has a result either
# positive or negative. Was: :element=>"flash", :text=>"Project saved"
# we may need to change it back if you really need a positive outcome, i.e.
# this step needs to fail if the project was not saved succesfully
selenium.click "submit_project_#{@project.id}",
:wait_for => :text,
:element => "flash",
:text => "Project saved"
:text => /(Project saved|1 error prohibited this project from being saved)/
end
When /^I edit the project name of "([^"]*)" to "([^"]*)"$/ do |project_current_name, project_new_name|
@project = @current_user.projects.find_by_name(project_current_name)
@project.should_not be_nil
When "I edit the project name to \"#{project_new_name}\""
end
Then /^I should see the bold text "([^\"]*)" in the project description$/ do |bold|