To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / object_daddy_helpers.rb @ 442:753f1380d6bc
History | View | Annotate | Download (1.09 KB)
| 1 |
module ObjectDaddyHelpers |
|---|---|
| 2 |
# TODO: Remove these three once everyone has ported their code to use the
|
| 3 |
# new object_daddy version with protected attribute support
|
| 4 |
def User.generate_with_protected(attributes={}) |
| 5 |
User.generate(attributes)
|
| 6 |
end
|
| 7 |
|
| 8 |
def User.generate_with_protected!(attributes={}) |
| 9 |
User.generate!(attributes)
|
| 10 |
end
|
| 11 |
|
| 12 |
def User.spawn_with_protected(attributes={}) |
| 13 |
User.spawn(attributes)
|
| 14 |
end
|
| 15 |
|
| 16 |
def User.add_to_project(user, project, roles) |
| 17 |
roles = [roles] unless roles.is_a?(Array) |
| 18 |
Member.generate!(:principal => user, :project => project, :roles => roles) |
| 19 |
end
|
| 20 |
|
| 21 |
# Generate the default Query
|
| 22 |
def Query.generate_default!(attributes={}) |
| 23 |
query = Query.spawn(attributes)
|
| 24 |
query.name ||= '_'
|
| 25 |
query.save! |
| 26 |
query |
| 27 |
end
|
| 28 |
|
| 29 |
# Generate an issue for a project, using it's trackers
|
| 30 |
def Issue.generate_for_project!(project, attributes={}) |
| 31 |
issue = Issue.spawn(attributes) do |issue| |
| 32 |
issue.project = project |
| 33 |
issue.tracker = project.trackers.first unless project.trackers.empty?
|
| 34 |
yield issue if block_given? |
| 35 |
end
|
| 36 |
issue.save! |
| 37 |
issue |
| 38 |
end
|
| 39 |
|
| 40 |
end
|