mingle-macro-development-toolkit 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,181 +1,109 @@
1
1
  #Copyright 2010 ThoughtWorks, Inc. All rights reserved.
2
- require 'erb'
3
2
 
4
3
  module FixtureLoaders
5
4
  class Base
6
- def initialize(mingle_file_name, macro_context=nil, alert_receiver=nil)
7
- @mingle_file_name = mingle_file_name
8
- @expanded_fixture = File.join(File.dirname(__FILE__), '..', 'fixtures', mingle_file_name)
9
- raise "No such project fixture! #{mingle_file_name}" unless File.exist?(@expanded_fixture)
5
+
6
+ def initialize(attributes)
7
+ @attributes = attributes
10
8
  end
11
-
9
+
12
10
  def load_fixtures_for(name)
13
- YAML::load(ERB.new(File.read("#{@expanded_fixture}/#{name}.yml")).result(binding))
14
- end
15
-
16
- def card_types_property_definitions_by_card_type_id_loader(card_type_id)
17
- LoadCardTypesPropertyDefinitionsByCardTypeId.new(card_type_id, @mingle_file_name)
18
- end
19
-
20
- def card_types_property_definitions_by_property_definition_id_loader(property_definition_id)
21
- LoadCardTypesPropertyDefinitionsByPropertyDefinitionId.new(property_definition_id, @mingle_file_name)
22
- end
23
-
24
- def values_by_property_definition_id_loader(property_definition_id)
25
- LoadValuesByPropertyDefinitionId.new(property_definition_id, @mingle_file_name)
26
- end
27
-
28
- def card_type_by_id_loader(card_type_id)
29
- LoadCardTypeById.new(card_type_id, @mingle_file_name)
11
+ path = File.join(File.dirname(__FILE__), '..', 'fixtures', "sample", "#{name}.yml")
12
+ YAML::load(File.read(path))
30
13
  end
31
-
32
- def property_definition_by_id_loader(property_definition_id)
33
- LoadPropertyDefinitionById.new(property_definition_id, @mingle_file_name)
34
- end
35
14
 
36
- def card_types_by_project_id_loader
37
- LoadCardTypesByProjectId.new(@mingle_file_name)
38
- end
39
-
40
- def property_definitions_by_project_id_loader
41
- LoadPropertyDefinitionsByProjectId.new(@mingle_file_name)
42
- end
43
-
44
- def team_by_project_id_loader
45
- LoadTeamByProjectId.new(@mingle_file_name)
15
+ def match?(record)
16
+ @attributes.all? { |key, value| value == record[key] }
46
17
  end
47
-
48
- def project_variables_by_project_id_loader
49
- LoadProjectVariablesByProjectId.new(@mingle_file_name)
50
- end
51
-
52
18
  end
53
19
 
54
20
  class ProjectLoader < Base
55
- def project
56
- project_attributes = load_fixtures_for('projects').first
57
- project = Mingle::Project.new(OpenStruct.new(project_attributes), nil)
58
- project.card_types_loader = card_types_by_project_id_loader
59
- project.property_definitions_loader = property_definitions_by_project_id_loader
60
- project.team_loader = team_by_project_id_loader
61
- project.project_variables_loader = project_variables_by_project_id_loader
62
- project
21
+ attr_reader :project
22
+
23
+ def initialize(identifier)
24
+ project_attributes = load_fixtures_for('projects').detect {|project| project['identifier'] == identifier }
25
+ @project = Mingle::Project.new(OpenStruct.new(project_attributes), nil)
26
+ project.card_types_loader = CardTypesLoader.new('project_id' => project_attributes['id'])
27
+ project.property_definitions_loader = PropertyDefinitionsLoader.new('project_id' => project_attributes['id'])
28
+ project.team_loader = TeamLoader.new('project_id' => project_attributes['id'])
29
+ project.project_variables_loader = ProjectVariablesLoader.new('project_id' => project_attributes['id'])
63
30
  end
64
31
  end
65
-
66
- class LoadCardTypesByProjectId < Base
32
+
33
+ class CardTypesLoader < Base
67
34
  def load
68
35
  load_fixtures_for('card_types').collect do |ct|
69
- card_type = Mingle::CardType.new(OpenStruct.new(ct))
70
- card_type.card_types_property_definitions_loader = card_types_property_definitions_by_card_type_id_loader(ct['id'])
71
- card_type
72
- end.sort_by(&:position)
73
- end
36
+ CardTypeLoader.new('id' => ct['id']) if match?(ct)
37
+ end.compact.sort_by { |loader| loader.card_type.position }
38
+ end
74
39
  end
75
-
76
- class LoadPropertyDefinitionsByProjectId < Base
40
+
41
+ class CardTypeLoader < Base
42
+ def card_type
43
+ @card_type ||= load
44
+ end
45
+
77
46
  def load
78
- load_fixtures_for('property_definitions').collect do |pd|
79
- property_definition = Mingle::PropertyDefinition.new(OpenStruct.new(pd))
80
- property_definition.card_types_property_definitions_loader = card_types_property_definitions_by_property_definition_id_loader(pd['id'])
81
- property_definition.values_loader = values_by_property_definition_id_loader(pd['id'])
82
- property_definition
83
- end
84
- end
47
+ record = load_fixtures_for('card_types').find {|ct| match?(ct)}
48
+ card_type = Mingle::CardType.new(OpenStruct.new(record))
49
+ card_type.card_types_property_definitions_loader = CardTypesPropertyDefinitionsLoader.new('card_type_id' => record['id'])
50
+ card_type
51
+ end
85
52
  end
86
-
87
- class LoadCardTypesPropertyDefinitionsByCardTypeId < Base
88
- def initialize(card_type_id, fixture_file_name)
89
- super(fixture_file_name)
90
- @card_type_id = card_type_id
91
- end
92
53
 
54
+ class PropertyDefinitionsLoader < Base
93
55
  def load
94
- load_fixtures_for('property_type_mappings').collect do |ctpd|
95
- next unless ctpd['card_type_id'] == @card_type_id
96
-
97
- card_type_property_definition = Mingle::CardTypePropertyDefinition.new(OpenStruct.new(ctpd))
98
- card_type_property_definition.card_type_loader = card_type_by_id_loader(ctpd['card_type_id'])
99
- card_type_property_definition.property_definition_loader = property_definition_by_id_loader(ctpd['property_definition_id'])
100
- card_type_property_definition
101
- end.compact.sort_by(&:position).compact
102
- end
103
-
104
- end
105
-
106
- class LoadCardTypesPropertyDefinitionsByPropertyDefinitionId < Base
107
- def initialize(property_definition_id, fixture_file_name)
108
- super(fixture_file_name)
109
- @property_definition_id = property_definition_id
110
- end
111
-
112
- def load
113
- load_fixtures_for('property_type_mappings').collect do |ctpd|
114
- next unless ctpd['property_definition_id'] == @property_definition_id
115
-
116
- card_type_property_definition = Mingle::CardTypePropertyDefinition.new(OpenStruct.new(ctpd))
117
- card_type_property_definition.card_type_loader = card_type_by_id_loader(ctpd['card_type_id'])
118
- card_type_property_definition.property_definition_loader = property_definition_by_id_loader(ctpd['property_definition_id'])
119
- card_type_property_definition
120
- end.compact.sort_by(&:position).compact
121
- end
122
-
56
+ load_fixtures_for('property_definitions').collect do |pd|
57
+ PropertyDefinitionLoader.new('id' => pd['id']) if match?(pd)
58
+ end.compact
59
+ end
123
60
  end
124
-
125
- class LoadCardTypeById < Base
126
- def initialize(card_type_id, fixture_file_name)
127
- super(fixture_file_name)
128
- @card_type_id = card_type_id
129
- end
130
-
61
+
62
+ class PropertyDefinitionLoader < Base
63
+ def property_definition
64
+ @property_definition ||= load
65
+ end
66
+
131
67
  def load
132
- yaml = load_fixtures_for('card_types').detect { |ct| ct['id'] == @card_type_id }
133
- ct = Mingle::CardType.new(OpenStruct.new(yaml))
134
- ct.card_types_property_definitions_loader = card_types_property_definitions_by_card_type_id_loader(yaml['id'])
135
- ct
136
- end
137
- end
138
-
139
- class LoadPropertyDefinitionById < Base
140
- def initialize(property_definition_id, fixture_file_name)
141
- super(fixture_file_name)
142
- @property_definition_id = property_definition_id
68
+ record = load_fixtures_for('property_definitions').find { |pd| match?(pd)}
69
+ property_definition = Mingle::PropertyDefinition.new(OpenStruct.new(record))
70
+ property_definition.card_types_property_definitions_loader = CardTypesPropertyDefinitionsLoader.new('property_definition_id' => record['id'])
71
+ property_definition.values_loader = PropertyValuesLoader.new('property_definition_id' => record['id'])
72
+ property_definition
143
73
  end
144
-
74
+ end
75
+
76
+ class PropertyValuesLoader < Base
145
77
  def load
146
- yaml = load_fixtures_for('property_definitions').detect { |pd| pd['id'] == @property_definition_id }
147
- pd = Mingle::PropertyDefinition.new(OpenStruct.new(yaml))
148
- pd.card_types_property_definitions_loader = card_types_property_definitions_by_property_definition_id_loader(yaml['id'])
149
- pd.values_loader = values_by_property_definition_id_loader(yaml['id'])
150
- pd
151
- end
78
+ load_fixtures_for('property_values').collect do |pv|
79
+ Mingle::PropertyValue.new(OpenStruct.new(pv)) if match?(pv)
80
+ end.compact
81
+ end
152
82
  end
153
83
 
154
- class LoadValuesByPropertyDefinitionId < Base
155
- def initialize(property_definition_id, fixture_file_name)
156
- super(fixture_file_name)
157
- @property_definition_id = property_definition_id
158
- end
159
-
84
+ class CardTypesPropertyDefinitionsLoader < Base
160
85
  def load
161
- result = load_fixtures_for('property_values').collect do |pv|
162
- next unless pv['property_definition_id'] == @property_definition_id
163
- property_value = Mingle::PropertyValue.new(OpenStruct.new(pv))
164
- property_value.property_definition_loader = property_definition_by_id_loader(pv['property_definition_id'])
165
- property_value
86
+ load_fixtures_for('property_type_mappings').collect do |mapping|
87
+ pd = PropertyDefinitionLoader.new('id' => mapping['property_definition_id']) if match?(mapping)
88
+ ct = CardTypeLoader.new('id' => mapping['card_type_id']) if match?(mapping)
89
+ OpenStruct.new(:card_type => ct.load, :property_definition => pd.load) if ct && pd
166
90
  end.compact
167
- end
91
+ end
168
92
  end
169
93
 
170
- class LoadTeamByProjectId < Base
94
+ class TeamLoader < Base
171
95
  def load
172
- load_fixtures_for('users').collect { |user| Mingle::User.new(OpenStruct.new(user)) }
173
- end
96
+ load_fixtures_for('users').collect do |user|
97
+ Mingle::User.new(OpenStruct.new(user)) if match?(user)
98
+ end.compact
99
+ end
174
100
  end
175
-
176
- class LoadProjectVariablesByProjectId < Base
101
+
102
+ class ProjectVariablesLoader < Base
177
103
  def load
178
- load_fixtures_for('project_variables').collect { |pv| Mingle::ProjectVariable.new(OpenStruct.new(pv)) }
179
- end
104
+ load_fixtures_for('project_variables').collect do |pv|
105
+ Mingle::ProjectVariable.new(OpenStruct.new(pv)) if match?(pv)
106
+ end.compact
107
+ end
180
108
  end
181
109
  end
@@ -1,45 +1,45 @@
1
- #Copyright 2008 ThoughtWorks, Inc. All rights reserved.
1
+ #Copyright 2010 ThoughtWorks, Inc. All rights reserved.
2
2
 
3
3
  require File.dirname(__FILE__) + '/unit_test_helper.rb'
4
4
 
5
5
  class FixtureLoaderTest < Test::Unit::TestCase
6
6
 
7
- TEST_FIXTURE = 'sample'
7
+ PROJECT = 'scrum_template_2_1'
8
8
 
9
9
  def test_should_load_direct_project_attributes_from_correct_fixture
10
- assert_not_nil project(TEST_FIXTURE)
11
- assert_equal 'scrum_template_2_1', project(TEST_FIXTURE).identifier
10
+ assert_not_nil project(PROJECT)
11
+ assert_equal 'scrum_template_2_1', project(PROJECT).identifier
12
12
  end
13
13
 
14
14
  def test_should_load_first_level_project_associations_from_correct_fixture
15
- assert_equal(['Release', 'Sprint', 'Story', 'Task', 'Defect', 'Feature', 'Epic Story'], project(TEST_FIXTURE).card_types.collect(&:name))
15
+ assert_equal(['Release', 'Sprint', 'Story', 'Task', 'Defect', 'Feature', 'Epic Story'], project(PROJECT).card_types.collect(&:name))
16
16
  end
17
17
 
18
18
  def test_should_load_second_level_project_associations_for_card_type_from_correct_fixture
19
- task_type = project(TEST_FIXTURE).card_types.detect { |ct| ct.name == 'Task' }
19
+ task_type = project(PROJECT).card_types.detect { |ct| ct.name == 'Task' }
20
20
  assert_equal(['Estimate - Planning', 'Risk', 'Added On', 'Priority', 'Owner', 'Task Estimate'], task_type.property_definitions.collect(&:name))
21
21
  end
22
22
 
23
23
  def test_should_load_second_level_project_associations_for_property_definition_from_correct_fixture
24
- priority_definition = project(TEST_FIXTURE).property_definitions.detect { |pd| pd.name == 'Priority' }
24
+ priority_definition = project(PROJECT).property_definitions.detect { |pd| pd.name == 'Priority' }
25
25
  assert_equal(['Story', 'Task', 'Defect'], priority_definition.card_types.collect(&:name))
26
26
  end
27
27
 
28
28
  def test_should_load_correct_values_for_property_definitions
29
- priority_definition = project(TEST_FIXTURE).property_definitions.detect { |pd| pd.name == 'Priority' }
29
+ priority_definition = project(PROJECT).property_definitions.detect { |pd| pd.name == 'Priority' }
30
30
  assert_equal ['High', 'Medium', 'Low'], priority_definition.values.collect(&:db_identifier)
31
31
  end
32
32
 
33
33
  def test_should_load_correct_team_members
34
- assert_equal ['groucho', 'harpo', 'karl'], project(TEST_FIXTURE).team.collect(&:login)
34
+ assert_equal ['groucho', 'harpo', 'karl'], project(PROJECT).team.collect(&:login)
35
35
  end
36
36
 
37
37
  def test_should_detect_project_variables
38
- assert_equal 'Release 3', project(TEST_FIXTURE).value_of_project_variable('Current Release')
38
+ assert_equal 'Release 3', project(PROJECT).value_of_project_variable('Current Release')
39
39
  end
40
40
 
41
41
  def test_should_raise_error_on_trying_to_call_values_for_anything_other_than_managed_or_user_properties
42
- added_on = project(TEST_FIXTURE).property_definitions.detect { |pd| pd.name == 'Added On' }
42
+ added_on = project(PROJECT).property_definitions.detect { |pd| pd.name == 'Added On' }
43
43
  assert_raise(RuntimeError) { added_on.values }
44
44
  end
45
45
  end
@@ -1,13 +1,14 @@
1
- #Copyright 2008 ThoughtWorks, Inc. All rights reserved.
1
+ #Copyright 2010 ThoughtWorks, Inc. All rights reserved.
2
2
 
3
3
  require 'test/unit'
4
4
  require 'macro_development_toolkit'
5
5
  require File.dirname(__FILE__) + '/fixture_loader'
6
6
 
7
7
  class Test::Unit::TestCase
8
-
8
+
9
9
  def project(name)
10
- @project ||= FixtureLoaders::ProjectLoader.new(name).project
11
- end
12
-
10
+ @projects ||= {}
11
+ @projects[name] ||= FixtureLoaders::ProjectLoader.new(name).project
12
+ end
13
+
13
14
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 3
8
- - 2
9
- version: 1.3.2
8
+ - 3
9
+ version: 1.3.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - ThoughtWorks Inc
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-13 00:00:00 -07:00
17
+ date: 2011-01-27 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -22,13 +22,13 @@ dependencies:
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 2
29
- - 0
30
- - 2
31
- version: 2.0.2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
32
  type: :runtime
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
@@ -46,19 +46,33 @@ dependencies:
46
46
  type: :development
47
47
  version_requirements: *id002
48
48
  - !ruby/object:Gem::Dependency
49
- name: hoe
49
+ name: gemcutter
50
50
  prerelease: false
51
51
  requirement: &id003 !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  segments:
56
- - 2
57
- - 6
58
- - 1
59
- version: 2.6.1
56
+ - 0
57
+ - 5
58
+ - 0
59
+ version: 0.5.0
60
60
  type: :development
61
61
  version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 5
72
+ - 0
73
+ version: 2.5.0
74
+ type: :development
75
+ version_requirements: *id004
62
76
  description: ""
63
77
  email:
64
78
  - support@thoughtworks.com
@@ -68,12 +82,12 @@ extensions: []
68
82
 
69
83
  extra_rdoc_files:
70
84
  - getting_started.txt
85
+ - README.txt
71
86
  - LICENSE.txt
72
87
  - History.txt
73
- - README.rdoc
74
88
  files:
75
89
  - getting_started.txt
76
- - README.rdoc
90
+ - README.txt
77
91
  - LICENSE.txt
78
92
  - History.txt
79
93
  - Rakefile
@@ -111,7 +125,7 @@ files:
111
125
  - example/integration_test.rb
112
126
  - example/integration_test_helper.rb
113
127
  has_rdoc: true
114
- homepage:
128
+ homepage: http://mingle-macros.rubyforge.org/
115
129
  licenses: []
116
130
 
117
131
  post_install_message: getting_started.txt