mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Fixed exception in preference model when todo xml api is used with show_from attribute
Signed-off-by: bsag <butshesagirl@rousette.org.uk>
This commit is contained in:
parent
b95e02e726
commit
5ee939ac47
3 changed files with 99 additions and 69 deletions
21
.gitignore
vendored
21
.gitignore
vendored
|
|
@ -1,14 +1,15 @@
|
|||
*.tmproj
|
||||
config/database.yml
|
||||
config/environment.rb
|
||||
config/deploy.rb
|
||||
log
|
||||
tmp
|
||||
db/data.yml
|
||||
db/*.sqlite3
|
||||
nbproject
|
||||
vendor/plugins/query_trace/
|
||||
db/schema.rb
|
||||
.dotest
|
||||
/.emacs-project
|
||||
config/database.yml
|
||||
config/deploy.rb
|
||||
config/environment.rb
|
||||
db/*.sqlite3
|
||||
db/data.yml
|
||||
db/schema.rb
|
||||
log
|
||||
nbproject
|
||||
public/javascripts/cache
|
||||
public/stylesheets/cache
|
||||
tmp
|
||||
vendor/plugins/query_trace/
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ class Preference < ActiveRecord::Base
|
|||
|
||||
def self.day_number_to_name_map
|
||||
{ 0 => "Sunday",
|
||||
1 => "Monday",
|
||||
2 => "Tuesday",
|
||||
3 => "Wednesday",
|
||||
4 => "Thursday",
|
||||
5 => "Friday",
|
||||
6 => "Saturday"}
|
||||
1 => "Monday",
|
||||
2 => "Tuesday",
|
||||
3 => "Wednesday",
|
||||
4 => "Thursday",
|
||||
5 => "Friday",
|
||||
6 => "Saturday"}
|
||||
end
|
||||
|
||||
def hide_completed_actions?
|
||||
|
|
@ -22,7 +22,16 @@ class Preference < ActiveRecord::Base
|
|||
|
||||
def parse_date(s)
|
||||
return nil if s.blank?
|
||||
user.at_midnight(Date.strptime(s, date_format))
|
||||
end
|
||||
date = nil
|
||||
|
||||
if s.is_a?(Time)
|
||||
date = s.to_date
|
||||
elsif s.is_a?(String)
|
||||
date = Date.strptime(s, date_format)
|
||||
else
|
||||
raise ArgumentError.new("Bad argument type:#{s.class}")
|
||||
end
|
||||
|
||||
user.at_midnight(date)
|
||||
end
|
||||
end
|
||||
|
|
@ -88,6 +88,26 @@ class TodosControllerTest < Test::Rails::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_create_todo_via_xml_show_from
|
||||
login_as(:admin_user)
|
||||
|
||||
assert_difference Todo, :count do
|
||||
xml = "<todo><description>Call Warren Buffet to find out how much he makes per day</description><project_id>#{projects(:timemachine).id}</project_id><context_id>#{contexts(:agenda).id}</context_id><show-from type=\"datetime\">#{1.week.from_now.xmlschema}</show-from></todo>"
|
||||
|
||||
#p parse_xml_body(xml)
|
||||
post :create, parse_xml_body(xml).update(:format => "xml")
|
||||
assert_response :created
|
||||
end
|
||||
end
|
||||
|
||||
def parse_xml_body(body)
|
||||
env = { 'rack.input' => StringIO.new(body),
|
||||
'HTTP_X_POST_DATA_FORMAT' => 'xml',
|
||||
'CONTENT_LENGTH' => body.size.to_s }
|
||||
ActionController::RackRequest.new(env).request_parameters
|
||||
end
|
||||
|
||||
|
||||
def test_fail_to_create_todo_via_xml
|
||||
login_as(:admin_user)
|
||||
# #try to create with no context, which is not valid
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue