mingle_events 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +6 -14
  2. data/Gemfile +1 -1
  3. data/lib/mingle_events/feed/category.rb +31 -18
  4. data/lib/mingle_events/feed/changes.rb +0 -1
  5. data/lib/mingle_events/processors/card_type_filter.rb +8 -8
  6. data/lib/mingle_events/xml.rb +18 -12
  7. data/lib/mingle_events/zip_directory.rb +6 -6
  8. data/test/mingle_events/entry_cache_test.rb +8 -8
  9. data/test/mingle_events/feed/author_test.rb +7 -7
  10. data/test/mingle_events/feed/category_test.rb +8 -8
  11. data/test/mingle_events/feed/changes_test.rb +87 -37
  12. data/test/mingle_events/feed/entry_test.rb +26 -26
  13. data/test/mingle_events/feed/links_test.rb +4 -4
  14. data/test/mingle_events/feed/page_test.rb +11 -11
  15. data/test/mingle_events/mingle_basic_auth_access_test.rb +1 -1
  16. data/test/mingle_events/mingle_hmac_auth_access_test.rb +1 -1
  17. data/test/mingle_events/mingle_oauth_access_test.rb +1 -1
  18. data/test/mingle_events/poller_test.rb +15 -15
  19. data/test/mingle_events/processors/author_filter_test.rb +21 -21
  20. data/test/mingle_events/processors/card_data_test.rb +61 -61
  21. data/test/mingle_events/processors/card_type_filter_test.rb +20 -24
  22. data/test/mingle_events/processors/category_filter_test.rb +6 -6
  23. data/test/mingle_events/processors/custom_property_filter_test.rb +17 -21
  24. data/test/mingle_events/processors/filter_test.rb +3 -3
  25. data/test/mingle_events/processors/pipeline_test.rb +4 -4
  26. data/test/mingle_events/processors/processor_test.rb +3 -3
  27. data/test/mingle_events/project_custom_properties_test.rb +23 -23
  28. data/test/mingle_events/project_event_fetcher_test.rb +23 -23
  29. data/test/mingle_events/xml_test.rb +6 -1
  30. data/test/mingle_events/zip_directory_test.rb +1 -1
  31. data/test/test_helper.rb +8 -3
  32. metadata +26 -25
@@ -2,48 +2,44 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
-
6
- class CardTypeFilterTest < Test::Unit::TestCase
7
-
8
- def setup
9
- @story_event = stub_event(true)
5
+
6
+ class CardTypeFilterTest < MiniTest::Test
7
+
8
+ def setup
9
+ @story_event = stub_event(true, {:card_type_name => 'story'})
10
10
  @page_event = stub_event(false)
11
- @bug_event = stub_event(true)
12
- @issue_event = stub_event(true)
13
-
14
- @card_data = {
15
- @story_event => {:card_type_name => 'story'},
16
- @bug_event => {:card_type_name => 'bug'},
17
- @issue_event => {:card_type_name => 'issue'}
18
- }
11
+ @bug_event = stub_event(true, {:card_type_name => 'bug'})
12
+ @issue_event = stub_event(true, {:card_type_name => 'issue'})
13
+
14
+ @card_data = {}
19
15
  def @card_data.for_card_event(card_event)
20
- self[card_event]
16
+ card_event.data
21
17
  end
22
-
18
+
23
19
  @filter = CardTypeFilter.new(['story', 'issue'], @card_data)
24
20
  end
25
-
21
+
26
22
  def test_does_not_match_non_card_events
27
23
  assert !@filter.match?(@page_event)
28
24
  end
29
-
25
+
30
26
  def test_match_on_card_type
31
27
  assert @filter.match?(@story_event)
32
28
  assert @filter.match?(@issue_event)
33
29
  assert !@filter.match?(@bug_event)
34
30
  end
35
-
31
+
36
32
  def test_does_not_match_deleted_cards
37
- @card_data[@story_event] = nil
33
+ @story_event.data = nil
38
34
  assert !@filter.match?(@story_event)
39
35
  end
40
-
36
+
41
37
  private
42
-
43
- def stub_event(is_card)
44
- OpenStruct.new(:card? => is_card)
38
+
39
+ def stub_event(is_card, data=nil)
40
+ OpenStruct.new(:card? => is_card, :data => data)
45
41
  end
46
-
42
+
47
43
  end
48
44
  end
49
45
  end
@@ -2,8 +2,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
- class CategoryFilterTest < Test::Unit::TestCase
6
-
5
+ class CategoryFilterTest < MiniTest::Test
6
+
7
7
  def test_match_against_one_category
8
8
  filter = CategoryFilter.new([Feed::Category::CARD])
9
9
  assert filter.match?(stub_event(1, [Feed::Category::CARD, Feed::Category::COMMENT_ADDITION]))
@@ -11,16 +11,16 @@ module MingleEvents
11
11
  assert !filter.match?(stub_event(1, [Feed::Category::COMMENT_ADDITION]))
12
12
  assert !filter.match?(stub_event(1, [Feed::Category::REVISION_COMMIT, Feed::Category::COMMENT_ADDITION]))
13
13
  end
14
-
14
+
15
15
  def test_match_against_multiple_categories
16
16
  filter = CategoryFilter.new([Feed::Category::CARD, Feed::Category::COMMENT_ADDITION])
17
17
  assert filter.match?(stub_event(1, [Feed::Category::CARD, Feed::Category::COMMENT_ADDITION]))
18
18
  assert !filter.match?(stub_event(1, [Feed::Category::CARD]))
19
19
  assert !filter.match?(stub_event(1, [Feed::Category::REVISION_COMMIT, Feed::Category::COMMENT_ADDITION]))
20
20
  end
21
-
22
- private
23
-
21
+
22
+ private
23
+
24
24
  def stub_event(id, categories)
25
25
  OpenStruct.new(:entry_id => id, :categories => categories)
26
26
  end
@@ -2,24 +2,20 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
-
6
- class CustomPropertyFilterTest < Test::Unit::TestCase
7
-
5
+
6
+ class CustomPropertyFilterTest < MiniTest::Test
7
+
8
8
  def setup
9
- @high_priority_event = stub_event(true)
9
+ @high_priority_event = stub_event(true, :custom_properties => {'Priority' => 'High'})
10
10
  @page_event = stub_event(false)
11
- @low_priority_event = stub_event(true)
12
- @high_severity_event = stub_event(true)
13
-
14
- @card_data = {
15
- @high_priority_event => {:custom_properties => {'Priority' => 'High'}},
16
- @low_priority_event => {:custom_properties => {'Priority' => 'Low'}},
17
- @high_severity_event => {:custom_properties => {'Severity' => 'High'}}
18
- }
11
+ @low_priority_event = stub_event(true, :custom_properties => {'Priority' => 'Low'})
12
+ @high_severity_event = stub_event(true, :custom_properties => {'Severity' => 'High'})
13
+
14
+ @card_data = {}
19
15
  def @card_data.for_card_event(card_event)
20
- self[card_event]
16
+ card_event.data
21
17
  end
22
-
18
+
23
19
  @filter = CustomPropertyFilter.new('Priority', 'High', @card_data)
24
20
  end
25
21
 
@@ -28,18 +24,18 @@ module MingleEvents
28
24
  assert !@filter.match?(@low_priority_event)
29
25
  assert !@filter.match?(@high_severity_event)
30
26
  end
31
-
27
+
32
28
  def test_does_not_match_delete_card
33
- @card_data[@high_priority_event] = nil
29
+ @high_priority_event.data = nil
34
30
  assert !@filter.match?(@high_priority_event)
35
31
  end
36
-
32
+
37
33
  private
38
-
39
- def stub_event(is_card)
40
- OpenStruct.new(:card? => is_card)
34
+
35
+ def stub_event(is_card, data=nil)
36
+ OpenStruct.new(:card? => is_card, :data => data)
41
37
  end
42
-
38
+
43
39
  end
44
40
  end
45
41
  end
@@ -2,12 +2,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
- class FilterTest < Test::Unit::TestCase
6
-
5
+ class FilterTest < MiniTest::Test
6
+
7
7
  def test_returns_events_that_match
8
8
  assert_equal([0,2,4], MatchEvenFilter.new.process_events([0,1,2,3,4,5]))
9
9
  end
10
-
10
+
11
11
  class MatchEvenFilter < Filter
12
12
  def match?(event)
13
13
  event % 2 == 0
@@ -2,19 +2,19 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
- class PipelineTest < Test::Unit::TestCase
6
-
5
+ class PipelineTest < MiniTest::Test
6
+
7
7
  def test_chains_all_processors
8
8
  events = [stub_event(100), stub_event(101), stub_event(102)]
9
9
  pipeline = Pipeline.new([DeleteLastProcessor.new, ReversingProcessor.new])
10
10
  processed_events = pipeline.process_events(events)
11
11
  assert_equal([101, 100], processed_events.map(&:entry_id))
12
12
  end
13
-
13
+
14
14
  def stub_event(id)
15
15
  OpenStruct.new(:entry_id => id)
16
16
  end
17
-
17
+
18
18
  class ReversingProcessor
19
19
  def process_events(events)
20
20
  events.reverse
@@ -2,12 +2,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_hel
2
2
 
3
3
  module MingleEvents
4
4
  module Processors
5
- class ProcessorTest < Test::Unit::TestCase
6
-
5
+ class ProcessorTest < MiniTest::Test
6
+
7
7
  def test_returns_events_that_match
8
8
  assert_equal([0,2,4], DoubleProcessor.new.process_events([0,1,2]))
9
9
  end
10
-
10
+
11
11
  class DoubleProcessor < Processor
12
12
  def process(event)
13
13
  event * 2
@@ -1,38 +1,38 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
2
2
 
3
3
  module MingleEvents
4
-
5
- class ProjectCustomPropertiesTest < Test::Unit::TestCase
6
-
4
+
5
+ class ProjectCustomPropertiesTest < MiniTest::Test
6
+
7
7
  def test_can_lookup_property_name_by_column_name
8
- property_definitions_xml = %{<?xml version="1.0" encoding="UTF-8"?>
9
- <property_definitions type="array">
10
- <property_definition>
11
- <name>Account</name>
12
- <data_type>string</data_type>
13
- <is_numeric type="boolean">false</is_numeric>
14
- <column_name>cp_account</column_name>
15
- </property_definition>
16
- <property_definition>
17
- <name>Account ID</name>
18
- <data_type>string</data_type>
19
- <is_numeric type="boolean">false</is_numeric>
20
- <column_name>cp_account_id</column_name>
21
- </property_definition>
22
- </property_definitions>
8
+ property_definitions_xml = %{<?xml version="1.0" encoding="UTF-8"?>
9
+ <property_definitions type="array">
10
+ <property_definition>
11
+ <name>Account</name>
12
+ <data_type>string</data_type>
13
+ <is_numeric type="boolean">false</is_numeric>
14
+ <column_name>cp_account</column_name>
15
+ </property_definition>
16
+ <property_definition>
17
+ <name>Account ID</name>
18
+ <data_type>string</data_type>
19
+ <is_numeric type="boolean">false</is_numeric>
20
+ <column_name>cp_account_id</column_name>
21
+ </property_definition>
22
+ </property_definitions>
23
23
  }
24
-
24
+
25
25
  dummy_mingle_access = StubMingleAccess.new
26
26
  dummy_mingle_access.register_page_content(
27
27
  URIParser.escape('/api/v2/projects/atlas/property_definitions.xml'),
28
28
  property_definitions_xml
29
29
  )
30
-
30
+
31
31
  project_custom_properties = ProjectCustomProperties.new(dummy_mingle_access, "atlas")
32
32
  assert_equal("Account ID", project_custom_properties.property_name_for_column("cp_account_id"))
33
-
33
+
34
34
  end
35
-
35
+
36
36
  end
37
-
37
+
38
38
  end
@@ -1,25 +1,25 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
2
2
 
3
3
  module MingleEvents
4
- class ProjectEventFetcherTest < Test::Unit::TestCase
5
-
4
+ class ProjectEventFetcherTest < MiniTest::Test
5
+
6
6
  def test_can_fetch_all_entries_and_write_to_disk_when_no_initial_state
7
7
  state_dir = temp_dir
8
- fetcher = ProjectEventFetcher.new('atlas', stub_mingle_access, state_dir)
9
-
8
+ fetcher = ProjectEventFetcher.new('atlas', stub_mingle_access, state_dir)
9
+
10
10
  latest_entries = fetcher.fetch_latest
11
11
  expected_latest_entries = [23, 97, 98, 99, 100, 101, 103].map{|n| entry(n)}
12
12
  assert_equal(expected_latest_entries, latest_entries.to_a)
13
13
  assert_equal entry(23), fetcher.first_entry_fetched
14
14
  assert_equal entry(103), fetcher.last_entry_fetched
15
15
  end
16
-
16
+
17
17
  def test_can_fetch_all_entries_and_write_to_disk_when_existing_state
18
18
  state_dir = temp_dir
19
19
  fetcher = ProjectEventFetcher.new('atlas', stub_mingle_access, state_dir)
20
-
20
+
21
21
  setup_current_state(23, 97, 97, fetcher)
22
-
22
+
23
23
  latest_entries = fetcher.fetch_latest
24
24
  expected_latest_entries = [98, 99, 100, 101, 103].map{|n| entry(n)}
25
25
 
@@ -27,7 +27,7 @@ module MingleEvents
27
27
  assert_equal entry(23), fetcher.first_entry_fetched
28
28
  assert_equal entry(103), fetcher.last_entry_fetched
29
29
  end
30
-
30
+
31
31
  def test_should_connect_existing_entries_and_newly_fetched_entries
32
32
  state_dir = temp_dir
33
33
  access = stub_mingle_access
@@ -93,18 +93,18 @@ module MingleEvents
93
93
  assert_equal entry(23), fetcher.first_entry_fetched
94
94
  assert_equal entry(103), fetcher.last_entry_fetched
95
95
  end
96
-
96
+
97
97
  def test_no_new_entries_with_no_current_state
98
98
  state_dir = temp_dir
99
99
  mingle_access = StubMingleAccess.new
100
100
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
101
101
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
102
-
102
+
103
103
  assert fetcher.fetch_latest.to_a.empty?
104
104
  assert_nil fetcher.first_entry_fetched
105
105
  assert_nil fetcher.last_entry_fetched
106
106
  end
107
-
107
+
108
108
  def test_set_current_state_to_now_if_no_current_state_when_project_has_previous_history
109
109
  state_dir = temp_dir
110
110
  mingle_access = stub_mingle_access
@@ -112,7 +112,7 @@ module MingleEvents
112
112
 
113
113
  fetcher.set_current_state_to_now_if_no_current_state
114
114
  assert fetcher.fetch_latest.to_a.empty?
115
-
115
+
116
116
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
117
117
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
118
118
 
@@ -134,16 +134,16 @@ module MingleEvents
134
134
  </entry>
135
135
  </feed>
136
136
  })
137
-
137
+
138
138
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
139
139
  end
140
-
140
+
141
141
  def test_set_current_state_to_now_if_no_current_state_is_ignored_if_there_is_already_local_current_state
142
142
  state_dir = temp_dir
143
143
  mingle_access = stub_mingle_access
144
144
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
145
145
  fetcher.fetch_latest # bring current state up to 103
146
-
146
+
147
147
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
148
148
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
149
149
 
@@ -165,11 +165,11 @@ module MingleEvents
165
165
  </entry>
166
166
  </feed>
167
167
  })
168
-
168
+
169
169
  fetcher.set_current_state_to_now_if_no_current_state
170
170
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
171
171
  end
172
-
172
+
173
173
  def test_subseuqnce_set_current_state_to_now_if_no_current_state_calls_when_project_initially_had_no_history_do_not_prevent_initial_events_from_being_seen
174
174
  state_dir = temp_dir
175
175
  mingle_access = StubMingleAccess.new
@@ -177,7 +177,7 @@ module MingleEvents
177
177
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
178
178
  fetcher.set_current_state_to_now_if_no_current_state
179
179
  assert fetcher.fetch_latest.to_a.empty?
180
-
180
+
181
181
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
182
182
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
183
183
 
@@ -195,18 +195,18 @@ module MingleEvents
195
195
  fetcher.set_current_state_to_now_if_no_current_state
196
196
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
197
197
  end
198
-
198
+
199
199
  private
200
-
201
- def setup_current_state(first_entry_id, second_entry_id, last_entry_id, fetcher)
200
+
201
+ def setup_current_state(first_entry_id, second_entry_id, last_entry_id, fetcher)
202
202
  first_entry = entry(first_entry_id)
203
203
  second_entry = entry(second_entry_id)
204
204
  last_entry = entry(last_entry_id)
205
205
  fetcher.entry_cache.write(first_entry, second_entry)
206
- fetcher.entry_cache.write(last_entry, nil)
206
+ fetcher.entry_cache.write(last_entry, nil)
207
207
  fetcher.entry_cache.update_current_state(first_entry, last_entry)
208
208
  end
209
-
209
+
210
210
  def entry(entry_id)
211
211
  entry_xml = %{
212
212
  <entry xmlns="http://www.w3.org/2005/Atom">
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
2
2
 
3
3
  module MingleEvents
4
- class XmlTest < Test::Unit::TestCase
4
+ class XmlTest < MiniTest::Test
5
5
  def test_get_inner_text
6
6
  assert_equal "s", Xml.parse("<a><b>s</b></a>").inner_text
7
7
  assert_equal "s", Xml.parse("<a><b>s</b></a>").inner_text("b")
@@ -38,6 +38,11 @@ module MingleEvents
38
38
 
39
39
  def test_element_to_hash
40
40
  assert_equal({:a => {:x => "s", :b => { :y => "t", :e => "0"}, :c => "1", :d => nil}}, Xml.parse('<a x="s"> <b y="t"> <e>0</e> </b> <c>1</c> <d nil="true" /> </a>').select("a").to_hash)
41
+
42
+ assert_equal({:a => 's'}, Xml.parse('<a x="y">s</a>').select('a').to_hash)
43
+ assert_equal({:a => "\u00A0"}, Xml.parse('<a>&#160;</a>').select('a').to_hash)
44
+ assert_equal({:a => { :x => 'y'}}, Xml.parse('<a x="y"></a>').select('a').to_hash)
45
+
41
46
  end
42
47
 
43
48
  def test_select_with_namespace
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper'))
2
2
 
3
3
  module MingleEvents
4
- class ZipDirectoryTest < Test::Unit::TestCase
4
+ class ZipDirectoryTest < MiniTest::Test
5
5
 
6
6
  def setup
7
7
  @dir = ZipDirectory.new("/tmp/foo")