Proposed new feature: array syntax in models {} block

3 views
Skip to first unread message

Alexey Tarasevich

unread,
Apr 18, 2011, 6:10:03 AM4/18/11
to active_factory
PROBLEM:
I want a syntax that allows me to associate tersely entries from
different factories with the same other entries.

EXAMPLE SITUATION:
Task may be in three states: complete, skipped or incomplete. A task
belongs_to a project and a user. A project belongs_to a user as well.
I want to test, that by default incomplete tasks are shown and others
tasks are hidden.

CURRENT ALTERNATIVE 1:

models {
_tasks = tasks({state: 'incomplete'}, {state: 'complete'}, {state:
'skipped'})
my - project - _tasks - my
}
incomplete_task, = tasks

test_only_task_shown project, incomplete_task

- difficult to read models {}
+ relatively terse

CURRENT ALTERNATIVE 2:

models {
project - incomplete_task - my
project - complete_task - my
project - skipped_task - my
project - my
}
test_only_task_shown project, incomplete_task

- verbose
+ clear models{} section

ALTERNATIVE TO IMPLEMENT:

models {
tasks = incomplete_task, complete_task, skipped_task
my - project - tasks - my
}
test_only_task_shown project, incomplete_task

+ argubly cleanest
+ most terse

...

def test_only_task_shown project, task
get project_path(project)
response.should have_tag "a.task", :text => task.text, :count => 1
end

factory :incomplete_task, :class => Task do
title "Incomplete Task Title"
state "incomplete"
end

QUESTION: Is it worth implementing?
Reply all
Reply to author
Forward
0 new messages