mingle_events 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ module MingleEvents
16
16
  MingleEvents.log.info("MingleEvents::Poller about to poll once...")
17
17
  @processors_by_project_identifier.each do |project_identifier, processors|
18
18
  fetcher = ProjectEventFetcher.new(project_identifier, @mingle_access)
19
- fetcher.reset if options[:clean]
19
+ fetcher.set_current_state_to_now_if_no_current_state
20
20
  latest_events = fetcher.fetch_latest.to_a
21
21
  processors.each{|p| p.process_events(latest_events)}
22
22
  end
@@ -20,9 +20,8 @@ module MingleEvents
20
20
  FileUtils.rm_rf(@state_dir)
21
21
  end
22
22
 
23
- # setup fetcher to only fetch new events, occuring beyond "right now"
24
- def reset_to_now
25
- return if last_entry_fetched
23
+ def set_current_state_to_now_if_no_current_state
24
+ return if has_current_state?
26
25
 
27
26
  latest_event = page_with_latest_entries.entries.first
28
27
  return if latest_event.nil?
@@ -74,13 +73,13 @@ module MingleEvents
74
73
  # only public to facilitate testing
75
74
  def update_current_state(oldest_new_entry, most_recent_new_entry)
76
75
  current_state = load_current_state
77
- if most_recent_new_entry
76
+ # if most_recent_new_entry
78
77
  current_state.merge!(:last_fetched_entry_info_file => file_for_entry(most_recent_new_entry))
79
78
  if current_state[:first_fetched_entry_info_file].nil?
80
79
  current_state.merge!(:first_fetched_entry_info_file => file_for_entry(oldest_new_entry))
81
80
  end
82
81
  File.open(current_state_file, 'w'){|out| YAML.dump(current_state, out)}
83
- end
82
+ # end
84
83
  end
85
84
 
86
85
  # only public to facilitate testing
@@ -116,6 +115,10 @@ module MingleEvents
116
115
  File.join(@state_dir, *relative_path_parts)
117
116
  end
118
117
 
118
+ def has_current_state?
119
+ File.exist?(current_state_file)
120
+ end
121
+
119
122
  def current_state_file
120
123
  File.expand_path(File.join(@state_dir, 'current_state.yml'))
121
124
  end
@@ -131,7 +134,7 @@ module MingleEvents
131
134
  end
132
135
 
133
136
  def load_current_state
134
- if File.exist?(current_state_file)
137
+ if has_current_state?
135
138
  YAML.load(File.new(current_state_file))
136
139
  else
137
140
  {:last_fetched_entry_info_file => nil, :first_fetched_entry_info_file => nil}
@@ -9,7 +9,11 @@ module MingleEvents
9
9
  processor_1 = DummyProcessor.new
10
10
  processor_2 = DummyProcessor.new
11
11
  poller = Poller.new(mingle_access, {'atlas' => [processor_1, processor_2]})
12
- poller.run_once(:clean => true)
12
+
13
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
14
+ poller.run_once
15
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', LATEST_EVENTS_XML)
16
+ poller.run_once
13
17
 
14
18
  expected_entry_ids = [
15
19
  'https://mingle.example.com/projects/atlas/events/index/23',
@@ -40,15 +40,7 @@ module MingleEvents
40
40
  def test_no_new_entries_with_no_current_state
41
41
  state_dir = temp_dir
42
42
  mingle_access = StubMingleAccess.new
43
- mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
44
- <?xml version="1.0" encoding="UTF-8"?>
45
- <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
46
- <title>Mingle Events: Blank Project</title>
47
- <id>https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml</id>
48
- <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="current"/>
49
- <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="self"/>
50
- <updated>2011-08-04T19:42:04Z</updated>
51
- </feed>})
43
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
52
44
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
53
45
 
54
46
  assert fetcher.fetch_latest.to_a.empty?
@@ -56,12 +48,12 @@ module MingleEvents
56
48
  assert_nil fetcher.last_entry_fetched
57
49
  end
58
50
 
59
- def test_reset_to_now_when_project_has_previous_history
51
+ def test_set_current_state_to_now_if_no_current_state_when_project_has_previous_history
60
52
  state_dir = temp_dir
61
53
  mingle_access = stub_mingle_access
62
54
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
63
55
 
64
- fetcher.reset_to_now
56
+ fetcher.set_current_state_to_now_if_no_current_state
65
57
  assert fetcher.fetch_latest.to_a.empty?
66
58
 
67
59
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
@@ -89,7 +81,7 @@ module MingleEvents
89
81
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
90
82
  end
91
83
 
92
- def test_reset_to_now_is_ignored_if_there_is_already_local_current_state
84
+ def test_set_current_state_to_now_if_no_current_state_is_ignored_if_there_is_already_local_current_state
93
85
  state_dir = temp_dir
94
86
  mingle_access = stub_mingle_access
95
87
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
@@ -117,26 +109,16 @@ module MingleEvents
117
109
  </feed>
118
110
  })
119
111
 
120
- fetcher.reset_to_now # if not ignored, next call would return no events rather than 104
112
+ fetcher.set_current_state_to_now_if_no_current_state
121
113
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
122
114
  end
123
115
 
124
- def test_reset_to_now_when_project_has_no_previous_history
116
+ 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
125
117
  state_dir = temp_dir
126
118
  mingle_access = StubMingleAccess.new
127
- mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
128
- <?xml version="1.0" encoding="UTF-8"?>
129
- <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
130
- <title>Mingle Events: Blank Project</title>
131
- <id>https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml</id>
132
- <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="current"/>
133
- <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="self"/>
134
- <updated>2011-08-04T19:42:04Z</updated>
135
- </feed>})
119
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
136
120
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
137
- fetcher.fetch_latest
138
-
139
- fetcher.reset_to_now
121
+ fetcher.set_current_state_to_now_if_no_current_state
140
122
  assert fetcher.fetch_latest.to_a.empty?
141
123
 
142
124
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
@@ -153,6 +135,7 @@ module MingleEvents
153
135
  </entry>
154
136
  </feed>
155
137
  })
138
+ fetcher.set_current_state_to_now_if_no_current_state
156
139
 
157
140
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
158
141
  end
data/test/test_helper.rb CHANGED
@@ -12,8 +12,19 @@ MingleEvents.log.level = Logger::WARN
12
12
 
13
13
  class Test::Unit::TestCase
14
14
 
15
+ EMPTY_EVENTS_XML = %{
16
+ <?xml version="1.0" encoding="UTF-8"?>
17
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
18
+ <title>Mingle Events: Blank Project</title>
19
+ <id>https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml</id>
20
+ <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="current"/>
21
+ <link href="https://mingle.example.com/api/v2/projects/blank_project/feeds/events.xml" rel="self"/>
22
+ <updated>2011-08-04T19:42:04Z</updated>
23
+ </feed>
24
+ }
25
+
15
26
  # page 3
16
- LATEST_PAGE_CONTENT = %{
27
+ LATEST_EVENTS_XML = %{
17
28
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
18
29
 
19
30
  <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml" rel="current"/>
@@ -42,7 +53,7 @@ class Test::Unit::TestCase
42
53
  }
43
54
 
44
55
  # page 2
45
- PAGE_2_CONTENT = %{
56
+ PAGE_2_EVENTS_XML = %{
46
57
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
47
58
 
48
59
  <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml" rel="current"/>
@@ -74,7 +85,7 @@ class Test::Unit::TestCase
74
85
  }
75
86
 
76
87
  # page 1
77
- PAGE_1_CONTENT = %{
88
+ PAGE_1_EVENTS_XML = %{
78
89
  <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
79
90
 
80
91
  <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml" rel="current"/>
@@ -92,14 +103,14 @@ class Test::Unit::TestCase
92
103
 
93
104
  def stub_mingle_access
94
105
  stub = StubMingleAccess.new
95
- stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml', LATEST_PAGE_CONTENT)
96
- stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=2', PAGE_2_CONTENT)
97
- stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1', PAGE_1_CONTENT)
98
- stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=3', LATEST_PAGE_CONTENT)
99
- stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml', LATEST_PAGE_CONTENT)
100
- stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=2', PAGE_2_CONTENT)
101
- stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=1', PAGE_1_CONTENT)
102
- stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=3', LATEST_PAGE_CONTENT)
106
+ stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml', LATEST_EVENTS_XML)
107
+ stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=2', PAGE_2_EVENTS_XML)
108
+ stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1', PAGE_1_EVENTS_XML)
109
+ stub.register_page_content('https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=3', LATEST_EVENTS_XML)
110
+ stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml', LATEST_EVENTS_XML)
111
+ stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=2', PAGE_2_EVENTS_XML)
112
+ stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=1', PAGE_1_EVENTS_XML)
113
+ stub.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=3', LATEST_EVENTS_XML)
103
114
 
104
115
  stub
105
116
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingle_events
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Rice