add some more tests

This commit is contained in:
Reinier Balt 2014-02-10 19:39:39 +01:00
parent b23338eaa2
commit 5de96d7eda
8 changed files with 281 additions and 65 deletions

View file

@ -13,6 +13,10 @@ module Tracks
@attributes[attribute.to_sym]
end
def [](attribute)
get attribute
end
def set(key, value)
@attributes[key.to_sym] = value
end
@ -21,6 +25,10 @@ module Tracks
@attributes[key.to_sym] ||= value
end
def []=(attribute, value)
set attribute, value
end
def except(key)
AttributeHandler.new(@user, @attributes.except(key.to_sym))
end
@ -30,19 +38,19 @@ module Tracks
end
def selector_key_present?(key)
@attributes.key?(key.to_sym)
key?(key)
end
def parse_date(date)
set(date, @user.prefs.parse_date(get(date)))
end
def parse_collection(object_type, relation, name)
def parse_collection(object_type, relation)
object = nil
new_object_created = false
if specified_by_name?(object_type)
object, new_object_created = find_or_create_by_name(relation, name)
object, new_object_created = find_or_create_by_name(relation, object_name(object_type))
# put id of object in @attributes, i.e. set :project_id to project.id
@attributes[object_type.to_s + "_id"] = object.id unless new_object_created
else
@ -53,6 +61,10 @@ module Tracks
return object, new_object_created
end
def object_name(object_type)
send("#{object_type}_name")
end
def attribute_with_id_of(object_type)
map = { project: 'project_id', context: 'context_id' }
get map[object_type]