get context list scenario passing

This commit is contained in:
Reinier Balt 2012-05-01 09:39:53 +02:00
parent c9d64e6f4b
commit 7bce774daa
9 changed files with 29 additions and 36 deletions

View file

@ -72,32 +72,19 @@ class ApplicationController < ActionController::Base
render :text => message, :status => status
end
# def rescue_action(exception)
# log_error(exception) if logger
# respond_to do |format|
# format.html do
# notify :warning, "An error occurred on the server."
# render :action => "index"
# end
# format.js { render :action => 'error' }
# format.xml { render :text => 'An error occurred on the server.' + $! }
# end
# end
# Returns a count of next actions in the given context or project The result
# is count and a string descriptor, correctly pluralised if there are no
# actions or multiple actions
#
def count_undone_todos_phrase(todos_parent, string="actions")
def count_undone_todos_phrase(todos_parent)
count = count_undone_todos(todos_parent)
deferred_count = count_deferred_todos(todos_parent)
if count == 0 && deferred_count > 0
word = deferred_count == 1 ? string.singularize : string.pluralize
word = "deferred&nbsp;" + word
return (deferred_count.to_s + "&nbsp;" + word).html_safe
word = "#{I18n.t('common.deferred')}&nbsp;#{I18n.t('common.actions_midsentence', :count => deferred_count)}"
return "#{deferred_count.to_s}&nbsp;#{word}".html_safe
else
word = count == 1 ? string.singularize : string.pluralize
return (count.to_s + "&nbsp;" + word).html_safe
word = I18n.t('common.actions_midsentence', :count => count)
return "#{count.to_s}&nbsp;#{word}".html_safe
end
end

View file

@ -12,6 +12,7 @@ class ContextsController < ApplicationController
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@new_context = current_user.contexts.build
init_not_done_counts(['context'])
# save all contexts here as @new_context will add an empty one to current_user.contexts
@all_contexts = @active_contexts + @hidden_contexts
@ -196,7 +197,6 @@ class ContextsController < ApplicationController
@no_hidden_contexts = @hidden_contexts.empty?
@active_count = @active_contexts.size
@hidden_count = @hidden_contexts.size
init_not_done_counts(['context'])
render
end
end

View file

@ -101,17 +101,17 @@ module ApplicationHelper
# actions or multiple actions
#
def count_undone_todos_phrase(todos_parent)
controller.count_undone_todos_phrase(todos_parent)
controller.count_undone_todos_phrase(todos_parent).html_safe
end
def count_undone_todos_phrase_text(todos_parent)
count_undone_todos_phrase(todos_parent).gsub("&nbsp;"," ")
count_undone_todos_phrase(todos_parent).gsub("&nbsp;"," ").html_safe
end
def count_undone_todos_and_notes_phrase(project)
s = count_undone_todos_phrase(project)
s += ", #{t('common.note', :count => project.note_count)}" unless project.note_count == 0
s
s.html_safe
end
def link_to_context(context, descriptor = sanitize(context.name))

View file

@ -1,15 +1,13 @@
<% context = context_form
@context = context
-%>
<% form_for(context, :html => {
<%= form_for(context, :html => {
:id => dom_id(context, 'edit_form'),
:class => "inline-form edit-project-form",
:method => :put }) do
-%>
<div id="edit_error_status"><%= error_messages_for("project") %></div>
<div id="edit_error_status"><%= get_list_of_error_messages_for(context) %></div>
<label for="context_name"><%= t 'contexts.context_name' %></label><br/>
<%= text_field('context', 'name', :class => 'context-name', :tabindex => next_tab_index) %><br/>

View file

@ -10,7 +10,7 @@ suppress_delete_button ||= false
<%= suppress_edit_button ? "" : link_to_edit_context(context, image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item")) -%>
<%= suppress_drag_handle ? "" : image_tag('grip.png', :width => '7', :height => '16', :border => '0', :title => t('common.drag_handle'), :class => 'grip')-%>
<div class="context_description">
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context) + ")" %>
<%= link_to_context( context ) %> <%= raw " (#{count_undone_todos_phrase(context)})" %>
</div>
</div>
<div id="<%= dom_id(context, 'edit') %>" class="edit-form" style="display:none;">

View file

@ -97,12 +97,6 @@ Feature: Manage the list of contexts
| active | @phone |
| hidden | @hidden |
@javascript
Scenario: Cannot add a context with comma in the name
When I go to the contexts page
And I add a new active context "foo, bar"
Then I should see "Name cannot contain the comma"
@javascript
Scenario: I can drag and drop to order the contexts
Given I have the following contexts

View file

@ -70,7 +70,15 @@ Then /^I should see the context name is "([^\"]*)"$/ do |context_name|
end
Then /^he should see that a context named "([^\"]*)" (is|is not) present$/ do |context_name, visible|
step "I should #{visible} \"#{context_name}\""
context = @current_user.contexts.find_by_name(context_name)
if visible == "is"
context.should_not be_nil
css = "div#context_#{context.id} div.context_description a"
page.should have_selector(css, :visible => true)
page.find(:css, css).text.should == context_name
else
page.should_not have_selector("div#context_#{context.id} div.context_description a", :visible => true) if context
end
end
Then /^I should (see|not see) empty message for (todo|completed todo|deferred todo)s of context/ do |visible, state|

View file

@ -3,7 +3,7 @@ Given /^I have no todos$/ do
end
Given /^I have a todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
context = @current_user.contexts.find_or_create(:name => context_name)
context = @current_user.contexts.find_or_create_by_name(context_name)
@todo = @current_user.todos.create!(:context_id => context.id, :description => description)
end
@ -88,7 +88,7 @@ Given /^I have ([0-9]+) deferred todos$/ do |count|
end
Given /^I have a deferred todo "([^"]*)" in the context "([^"]*)"$/ do |description, context_name|
context = @current_user.contexts.find_or_create(:name => context_name)
context = @current_user.contexts.find_or_create_by_name(context_name)
todo = @current_user.todos.create!(:context_id => context.id, :description => description)
todo.show_from = @current_user.time + 1.week
todo.save!

View file

@ -20,6 +20,12 @@ class ContextsControllerTest < ActionController::TestCase
assert_template "contexts/show"
end
def test_get_edit_form_using_xhr
login_as(:admin_user)
xhr :get, :edit, :id => contexts(:errand).id
assert_response 200
end
def test_create_context_via_ajax_increments_number_of_context
login_as :other_user
assert_ajax_create_increments_count '@newcontext'