mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-17 20:58:09 +01:00
make functional tests for context controller run
This commit is contained in:
parent
76340b780c
commit
59a4d5ede0
10 changed files with 225 additions and 182 deletions
|
|
@ -25,16 +25,21 @@ class ContextsController < ApplicationController
|
|||
format.html &render_contexts_html
|
||||
format.m &render_contexts_mobile
|
||||
format.xml { render :xml => @all_contexts.to_xml( :except => :user_id ) }
|
||||
format.rss &render_contexts_rss_feed
|
||||
format.atom &render_contexts_atom_feed
|
||||
format.rss do
|
||||
@feed_title = 'Tracks Contexts'
|
||||
@feed_description = "Lists all the contexts for #{current_user.display_name}"
|
||||
end
|
||||
format.atom do
|
||||
@feed_title = 'Tracks Contexts'
|
||||
@feed_description = "Lists all the contexts for #{current_user.display_name}"
|
||||
end
|
||||
format.text do
|
||||
@all_contexts = current_user.contexts.all
|
||||
render :action => 'index', :layout => false, :content_type => Mime::TEXT
|
||||
end
|
||||
format.autocomplete &render_autocomplete
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@contexts = current_user.contexts(true)
|
||||
if @context.nil?
|
||||
|
|
@ -60,15 +65,10 @@ class ContextsController < ApplicationController
|
|||
#
|
||||
def create
|
||||
if params[:format] == 'application/xml' && params['exception']
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
render_failure "Expected post format is valid xml like so: <context><name>context name</name></context>.", 400
|
||||
return
|
||||
end
|
||||
@context = current_user.contexts.build
|
||||
params_are_invalid = true
|
||||
if (params['context'] || (params['request'] && params['request']['context']))
|
||||
@context.attributes = params['context'] || params['request']['context']
|
||||
params_are_invalid = false
|
||||
end
|
||||
@context = current_user.contexts.build(params['context'])
|
||||
@saved = @context.save
|
||||
@context_not_done_counts = { @context.id => 0 }
|
||||
respond_to do |format|
|
||||
|
|
@ -76,9 +76,7 @@ class ContextsController < ApplicationController
|
|||
@down_count = current_user.contexts.size
|
||||
end
|
||||
format.xml do
|
||||
if @context.new_record? && params_are_invalid
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
elsif @context.new_record?
|
||||
if @context.new_record?
|
||||
render_failure @context.errors.to_xml, 409
|
||||
else
|
||||
head :created, :location => context_url(@context)
|
||||
|
|
@ -233,21 +231,6 @@ class ContextsController < ApplicationController
|
|||
render :action => 'mobile_show_context'
|
||||
end
|
||||
end
|
||||
|
||||
def render_contexts_rss_feed
|
||||
lambda do
|
||||
render_rss_feed_for current_user.contexts.all, :feed => feed_options,
|
||||
:item => { :description => lambda { |c| @template.summary(c, count_undone_todos_phrase(c)) } }
|
||||
end
|
||||
end
|
||||
|
||||
def render_contexts_atom_feed
|
||||
lambda do
|
||||
render_atom_feed_for current_user.contexts.all, :feed => feed_options,
|
||||
:item => { :description => lambda { |c| @template.summary(c, count_undone_todos_phrase(c)) },
|
||||
:author => lambda { |c| nil } }
|
||||
end
|
||||
end
|
||||
|
||||
def render_autocomplete
|
||||
lambda do
|
||||
|
|
|
|||
|
|
@ -29,10 +29,8 @@ module ContextsHelper
|
|||
})
|
||||
end
|
||||
|
||||
|
||||
def summary(context, undone_todo_count)
|
||||
content_tag(:p, "#{undone_todo_count}. Context is #{context.hidden? ? 'Hidden' : 'Active'}.")
|
||||
def context_summary(context, undone_todo_count)
|
||||
content_tag(:p, "#{undone_todo_count}. Context is #{context.hidden? ? 'Hidden' : 'Active'}.".html_safe)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ module ProjectsHelper
|
|||
})
|
||||
end
|
||||
|
||||
def summary(project)
|
||||
def project_summary(project)
|
||||
project_description = ''
|
||||
project_description += Tracks::Utils.render_text( project.description ) unless project.description.blank?
|
||||
project_description += content_tag(:p,
|
||||
|
|
|
|||
|
|
@ -16,14 +16,6 @@ class Context < ActiveRecord::Base
|
|||
validates_length_of :name, :maximum => 255, :message => "context name must be less than 256 characters"
|
||||
validates_uniqueness_of :name, :message => "already exists", :scope => "user_id"
|
||||
|
||||
def self.feed_options(user)
|
||||
# TODO: move to view or helper
|
||||
{
|
||||
:title => 'Tracks Contexts',
|
||||
:description => "Lists all the contexts for #{user.display_name}"
|
||||
}
|
||||
end
|
||||
|
||||
def self.null_object
|
||||
NullContext.new
|
||||
end
|
||||
|
|
|
|||
12
app/views/contexts/index.atom.builder
Normal file
12
app/views/contexts/index.atom.builder
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
atom_feed do |feed|
|
||||
feed.title(@feed_title)
|
||||
feed.subtitle(@feed_description)
|
||||
feed.updated(@all_contexts.last.updated_at)
|
||||
|
||||
@all_contexts.each do |context|
|
||||
feed.entry(context) do |entry|
|
||||
entry.title(h(context.name))
|
||||
entry.content(context_summary(context, count_undone_todos_phrase(context)), :type => :html)
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/views/contexts/index.rss.builder
Normal file
20
app/views/contexts/index.rss.builder
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.rss :version => "2.0" do
|
||||
xml.channel do
|
||||
xml.title @feed_title
|
||||
xml.description @feed_description
|
||||
xml.link contexts_url
|
||||
xml.language 'en-us'
|
||||
xml.ttl 40
|
||||
|
||||
@all_contexts.each do |context|
|
||||
xml.item do
|
||||
xml.title h(context.title)
|
||||
xml.description context_summary(context, count_undone_todos_phrase(context))
|
||||
xml.pubDate context.created_at.to_s(:rfc822)
|
||||
xml.link context_url(context)
|
||||
xml.guid context_url(context)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue