Mercurial > hg > soundsoftware-site
comparison .svn/pristine/94/94e11c870fc879bb4baf66f3ed996a69a2f5f60d.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 module ObjectHelpers | |
2 def User.generate!(attributes={}) | |
3 @generated_user_login ||= 'user0' | |
4 @generated_user_login.succ! | |
5 user = User.new(attributes) | |
6 user.login = @generated_user_login if user.login.blank? | |
7 user.mail = "#{@generated_user_login}@example.com" if user.mail.blank? | |
8 user.firstname = "Bob" if user.firstname.blank? | |
9 user.lastname = "Doe" if user.lastname.blank? | |
10 yield user if block_given? | |
11 user.save! | |
12 user | |
13 end | |
14 | |
15 def User.add_to_project(user, project, roles=nil) | |
16 roles = Role.find(1) if roles.nil? | |
17 roles = [roles] unless roles.is_a?(Array) | |
18 Member.create!(:principal => user, :project => project, :roles => roles) | |
19 end | |
20 | |
21 def Group.generate!(attributes={}) | |
22 @generated_group_name ||= 'Group 0' | |
23 @generated_group_name.succ! | |
24 group = Group.new(attributes) | |
25 group.name = @generated_group_name if group.name.blank? | |
26 yield group if block_given? | |
27 group.save! | |
28 group | |
29 end | |
30 | |
31 def Project.generate!(attributes={}) | |
32 @generated_project_identifier ||= 'project-0000' | |
33 @generated_project_identifier.succ! | |
34 project = Project.new(attributes) | |
35 project.name = @generated_project_identifier if project.name.blank? | |
36 project.identifier = @generated_project_identifier if project.identifier.blank? | |
37 yield project if block_given? | |
38 project.save! | |
39 project | |
40 end | |
41 | |
42 def Tracker.generate!(attributes={}) | |
43 @generated_tracker_name ||= 'Tracker 0' | |
44 @generated_tracker_name.succ! | |
45 tracker = Tracker.new(attributes) | |
46 tracker.name = @generated_tracker_name if tracker.name.blank? | |
47 yield tracker if block_given? | |
48 tracker.save! | |
49 tracker | |
50 end | |
51 | |
52 def Role.generate!(attributes={}) | |
53 @generated_role_name ||= 'Role 0' | |
54 @generated_role_name.succ! | |
55 role = Role.new(attributes) | |
56 role.name = @generated_role_name if role.name.blank? | |
57 yield role if block_given? | |
58 role.save! | |
59 role | |
60 end | |
61 | |
62 def Issue.generate!(attributes={}) | |
63 issue = Issue.new(attributes) | |
64 issue.project ||= Project.find(1) | |
65 issue.tracker ||= issue.project.trackers.first | |
66 issue.subject = 'Generated' if issue.subject.blank? | |
67 issue.author ||= User.find(2) | |
68 yield issue if block_given? | |
69 issue.save! | |
70 issue | |
71 end | |
72 | |
73 # Generates an issue with 2 children and a grandchild | |
74 def Issue.generate_with_descendants!(attributes={}) | |
75 issue = Issue.generate!(attributes) | |
76 child = Issue.generate!(:project => issue.project, :subject => 'Child1', :parent_issue_id => issue.id) | |
77 Issue.generate!(:project => issue.project, :subject => 'Child2', :parent_issue_id => issue.id) | |
78 Issue.generate!(:project => issue.project, :subject => 'Child11', :parent_issue_id => child.id) | |
79 issue.reload | |
80 end | |
81 | |
82 def Journal.generate!(attributes={}) | |
83 journal = Journal.new(attributes) | |
84 journal.user ||= User.first | |
85 journal.journalized ||= Issue.first | |
86 yield journal if block_given? | |
87 journal.save! | |
88 journal | |
89 end | |
90 | |
91 def Version.generate!(attributes={}) | |
92 @generated_version_name ||= 'Version 0' | |
93 @generated_version_name.succ! | |
94 version = Version.new(attributes) | |
95 version.name = @generated_version_name if version.name.blank? | |
96 yield version if block_given? | |
97 version.save! | |
98 version | |
99 end | |
100 | |
101 def AuthSource.generate!(attributes={}) | |
102 @generated_auth_source_name ||= 'Auth 0' | |
103 @generated_auth_source_name.succ! | |
104 source = AuthSource.new(attributes) | |
105 source.name = @generated_auth_source_name if source.name.blank? | |
106 yield source if block_given? | |
107 source.save! | |
108 source | |
109 end | |
110 | |
111 def Board.generate!(attributes={}) | |
112 @generated_board_name ||= 'Forum 0' | |
113 @generated_board_name.succ! | |
114 board = Board.new(attributes) | |
115 board.name = @generated_board_name if board.name.blank? | |
116 board.description = @generated_board_name if board.description.blank? | |
117 yield board if block_given? | |
118 board.save! | |
119 board | |
120 end | |
121 end |