dash-mario 0.16 → 0.17

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.
@@ -6,7 +6,7 @@ module DashFu::Mario
6
6
  def setup(source, params)
7
7
  gem_name = params["gem_name"].to_s.strip
8
8
  source["source.name"] = "RubyGems: #{gem_name}"
9
- source["metric.columns"] = [{ :id=>"downloads", :label=>"Downloads" }]
9
+ source["metric.columns"] = [{ id: "downloads", label: "Downloads" }]
10
10
  source["metric.totals"] = true
11
11
  source["gem_name"] = gem_name
12
12
  end
@@ -15,40 +15,39 @@ module DashFu::Mario
15
15
  raise "Missing gem name" if source["gem_name"].blank?
16
16
  end
17
17
 
18
- def update(source, request)
18
+ def update(source, request, callback)
19
19
  gem_name = source["gem_name"]
20
- uri = URI.parse("http://rubygems.org/api/v1/gems/#{Rack::Utils.escape gem_name}.json")
21
- case response = Net::HTTP.get_response(uri)
22
- when Net::HTTPOK
23
- json = JSON.parse(response.body) rescue nil
24
- when Net::HTTPNotFound
25
- raise "Could not find the Gem #{gem_name}"
26
- end
27
- unless json
28
- logger.error "RubyGems: #{response.code} #{response.message}"
29
- raise "Last request didn't go as expected, trying again later"
30
- end
31
-
32
- if source["version"]
33
- current, latest = Gem::Version.new(source["version"]), Gem::Version.new(json["version"])
34
- if latest > current
35
- html = "released <a href=\"http://rubygems.org/gems/#{gem_name}/versions/#{latest}\">#{gem_name} version #{latest}</a>."
36
- person = { :fullname=>"RubyGems", :identities=>"url:http://rubygems.org/", :photo_url=>"http://dash-fu.com/images/sources/ruby.png" }
37
- yield :activity=>{ :uid=>"#{gem_name}-#{latest}", :url=>"http://rubygems.org/gems/#{gem_name}",
38
- :html=>html, :tags=>%w{release}, :person=>person }
20
+ session "rubygems.org" do |http|
21
+ http.get_json "/api/v1/gems/#{gem_name}.json" do |status, json|
22
+ case status
23
+ when 200
24
+ if source["version"]
25
+ current, latest = Gem::Version.new(source["version"]), Gem::Version.new(json["version"])
26
+ if latest > current
27
+ html = "released <a href=\"http://rubygems.org/gems/#{gem_name}/versions/#{latest}\">#{gem_name} version #{latest}</a>."
28
+ person = { fullname: "RubyGems", identities: "url:http://rubygems.org/", photo_url: "http://dash-fu.com/images/sources/ruby.png" }
29
+ callback.activity! uid: "#{gem_name}-#{latest}", url: "http://rubygems.org/gems/#{gem_name}",
30
+ html: html, tags: %w{release}, person: person
31
+ end
32
+ end
33
+ source["version"] = json["version"]
34
+ source.update json.slice(*%w{homepage_uri project_uri info authors info})
35
+ callback.set! downloads: json["downloads"]
36
+ when 404
37
+ callback.error! "Could not find the Gem #{gem_name}"
38
+ else
39
+ callback.error! "Last request didn't go as expected, trying again later"
40
+ end
39
41
  end
40
42
  end
41
- source["version"] = json["version"]
42
- source.update json.slice(*%w{homepage_uri project_uri info authors info})
43
- yield :set=>{ :downloads=>json["downloads"] }
44
43
  end
45
44
 
46
45
  def meta(source)
47
- [ { :title=>"Project", :text=>source["gem_name"], :url=>source["homepage_uri"] || source["project_uri"] },
48
- { :text=>source["info"] },
49
- { :title=>"Version", :text=>source["version"] },
50
- { :title=>"Authors", :text=>source["authors"] },
51
- { :title=>"Source", :text=>"RubyGems", :url=>source["project_uri"] } ]
46
+ [ { title: "Project", text: source["gem_name"], url: source["homepage_uri"] || source["project_uri"] },
47
+ { text: source["info"] },
48
+ { title: "Version", text: source["version"] },
49
+ { title: "Authors", text: source["authors"] },
50
+ { title: "Source", text: "RubyGems", url: source["project_uri"] } ]
52
51
  end
53
52
 
54
53
  end
@@ -21,7 +21,7 @@ test DashFu::Mario::Backtweets do
21
21
  end
22
22
 
23
23
  should "capture tweets" do
24
- assert subject.columns.include?(:id=>"tweets", :label=>"Tweets")
24
+ assert subject.columns.include?(id: "tweets", label: "Tweets")
25
25
  end
26
26
  end
27
27
  end
@@ -48,96 +48,92 @@ test DashFu::Mario::Backtweets do
48
48
  end
49
49
 
50
50
  should "properly encode URL" do
51
- stub_request(:get, /backtweets.com/).to_return :body=>interactions.first.response.body
51
+ stub_request(:get, /backtweets.com/).to_return body: interactions.first.response.body
52
52
  source.setup "url"=>"need&this=encoded"
53
53
  source.update
54
54
  assert_requested :get, "http://backtweets.com/search.json?key=#{mario.send :api_key}&q=need%26this%3Dencoded"
55
55
  end
56
56
 
57
57
  should "handle errors" do
58
- stub_request(:get, interactions.first.uri).to_return :status=>500
59
- assert_raise(RuntimeError) { source.update }
58
+ stub_request(:get, interactions.first.uri).to_return status: 500
59
+ source.update
60
60
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
61
61
  end
62
62
 
63
- should "handle invlid document entity" do
64
- stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
65
- assert_raise(RuntimeError) { source.update }
63
+ should "handle invalid document entity" do
64
+ stub_request(:get, interactions.first.uri).to_return body: "Not JSON"
65
+ source.update
66
66
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
67
67
  end
68
68
 
69
69
  should "capture number of tweets" do
70
70
  source.update
71
- assert_equal({ :tweets=>11 }, source.metric.values)
71
+ assert_equal({ tweets: 2 }, source.metric.values)
72
72
  end
73
73
 
74
- should "ignore previous tweets" do
75
- source.update
76
- assert source.activities.empty?
77
- end
74
+ context "activity" do
75
+ setup { source.update }
76
+ subject { source.activity }
78
77
 
79
- context "repeating" do
80
- setup do
81
- source.update
82
- second = interactions.last
83
- stub_request(:get, second.uri).to_return :body=>second.response.body
84
- source.update
78
+ should "capture tweet identifier" do
79
+ assert_equal "20959239143", subject.uid
85
80
  end
86
81
 
87
- should "capture new tweets" do
88
- assert_equal 2, source.activities.count
82
+ should "capture tweet text" do
83
+ assert_equal <<-HTML, subject.html
84
+ <a href="http://twitter.com/dude/20959239143">tweeted</a>:
85
+ <blockquote>Super awesome <a href="http://vanity.labnotes.org/">http://j.mp/aOrUnsz</a></blockquote>
86
+ HTML
89
87
  end
90
88
 
91
- context "activity" do
92
- subject { source.activity }
89
+ should "capture tweet URL" do
90
+ assert_equal "http://twitter.com/dude/20959239143", subject.url
91
+ end
93
92
 
94
- should "capture tweet identifier" do
95
- assert_equal "20959239300", subject.uid
96
- end
93
+ should "capture tweet timestamp" do
94
+ assert_equal Time.parse("2010-8-12T08:30:04").utc, subject.timestamp
95
+ end
97
96
 
98
- should "capture tweet text" do
99
- assert_equal <<-HTML, subject.html
100
- <a href="http://twitter.com/assaf/20959239300">tweeted</a>:
101
- <blockquote>Super awesome <a href="http://vanity.labnotes.org/">http://j.mp/aOrUnsz</a></blockquote>
102
- HTML
103
- end
97
+ should "tag as tweeter and mention" do
98
+ assert_contains subject.tags, "twitter"
99
+ assert_contains subject.tags, "mention"
100
+ end
104
101
 
105
- should "capture tweet URL" do
106
- assert_equal "http://twitter.com/assaf/20959239300", subject.url
107
- end
102
+ should "be valid" do
103
+ assert subject.valid?
104
+ end
108
105
 
109
- should "capture tweet timestamp" do
110
- assert_equal Time.parse("2010-8-22T05:00:04").utc, subject.timestamp
111
- end
106
+ context "author" do
107
+ subject { source.activity.person }
112
108
 
113
- should "tag as tweeter and mention" do
114
- assert_contains subject.tags, "twitter"
115
- assert_contains subject.tags, "mention"
109
+ should "capture full name" do
110
+ assert_equal "dude", subject.fullname
116
111
  end
117
112
 
118
- should "be valid" do
119
- assert subject.valid?
113
+ should "capture screen name" do
114
+ assert_contains subject.identities, "twitter.com:dude"
120
115
  end
121
116
 
122
- context "author" do
123
- subject { source.activity.person }
124
-
125
- should "capture full name" do
126
- assert_equal "assaf", subject.fullname
127
- end
117
+ should "capture photo" do
118
+ assert_equal "http://img.tweetimag.es/i/dude_n", subject.photo_url
119
+ end
120
+ end
121
+ end
128
122
 
129
- should "capture screen name" do
130
- assert_contains subject.identities, "twitter.com:assaf"
131
- end
123
+ context "repeating" do
124
+ setup do
125
+ source.update
126
+ second = interactions.last
127
+ stub_request(:get, second.uri).to_return body: second.response.body
128
+ source.update
129
+ end
132
130
 
133
- should "capture photo" do
134
- assert_equal "http://twitter.com/account/profile_image/assaf", subject.photo_url
135
- end
136
- end
131
+ should "capture new tweets" do
132
+ assert_equal 3, source.activities.count
133
+ assert_match "The last of its kind", source.activity.html
137
134
  end
138
135
 
139
136
  end
140
-
141
137
  end
142
138
 
143
139
 
@@ -146,7 +142,7 @@ test DashFu::Mario::Backtweets do
146
142
  subject { source.meta }
147
143
 
148
144
  should "link to search results" do
149
- assert subject.include?(:text=>"Search yourself", :url=>"http://backtweets.com/search?q=vanity.labnotes.org")
145
+ assert subject.include?(text: "Search yourself", url: "http://backtweets.com/search?q=vanity.labnotes.org")
150
146
  end
151
147
  end
152
148
  end
@@ -22,8 +22,20 @@
22
22
  - Sat, 21 Aug 2010 05:31:10 GMT
23
23
  content-length:
24
24
  - "4427"
25
- body: "{\"totalresults\":\"11\",\"startindex\":1,\"itemsperpage\":25,\"tweets\":[{\"tweet_id\":\"20959239143\",\"tweet_from_user_id\":1501751,\"tweet_from_user\":\"olivM\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/305156692\\/ls_3001_author30_normal.jpg\",\"tweet_created_at\":\"2010-08-12 08:30:04\",\"tweet_text\":\"Vanity : an Experiment Driven Development framework for Rails : <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/j.mp\\/aOrUnsz<\\/a> #AB_testing\"},{\"tweet_id\":\"20959192608\",\"tweet_from_user_id\":1501751,\"tweet_from_user\":\"olivM\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/305156692\\/ls_3001_author30_normal.jpg\",\"tweet_created_at\":\"2010-08-12 08:29:02\",\"tweet_text\":\"Vanity : a serious A\\/B testing framework for Rails : <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/j.mp\\/aOrUns<\\/a> #AB_testing\"},{\"tweet_id\":\"20449872279\",\"tweet_from_user_id\":6291182,\"tweet_from_user\":\"tpitale\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/972769472\\/tpitale_bio3_normal.jpg\",\"tweet_created_at\":\"2010-08-06 07:19:34\",\"tweet_text\":\"RT @assaf: Just pushed Vanity 1.4 <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/vanity.labnotes.org\\/<\\/a>\"},{\"tweet_id\":\"20449849489\",\"tweet_from_user_id\":2367111,\"tweet_from_user\":\"assaf\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/30105312\\/profile-photo_normal.jpg\",\"tweet_created_at\":\"2010-08-06 07:19:01\",\"tweet_text\":\"Just pushed Vanity 1.4 <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/vanity.labnotes.org\\/<\\/a>\"},{\"tweet_id\":\"20162966374\",\"tweet_from_user_id\":657013,\"tweet_from_user\":\"pelargir\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/767173052\\/5775_128094836287_699146287_3006700_7689164_n_normal.jpg\",\"tweet_created_at\":\"2010-08-02 19:42:59\",\"tweet_text\":\"Started an A\\/B test for teascript.com using the Vanity gem for Rails. Impressed so far. <a href=\\\"http:\\/\\/vanity.labnotes.org\\\">http:\\/\\/vanity.labnotes.org<\\/a>\"},{\"tweet_id\":\"19699432401\",\"tweet_from_user_id\":2367111,\"tweet_from_user\":\"assaf\",\"tweet_profile_image_url\":\"http:\\/\\/a0.twimg.com\\/profile_images\\/30105312\\/profile-photo_normal.jpg\",\"tweet_created_at\":\"2010-07-28 00:56:07\",\"tweet_text\":\"It took a lot of tinkering, but wkhtmltopdf eventually pulled it. Vanity PDF for offline reading <a href=\\\"http:\\/\\/vanity.labnotes.org\\/vanity.pdf\\\">http:\\/\\/vanity.labnotes.org\\/vanity.pdf<\\/a>\"},{\"tweet_id\":\"19590974913\",\"tweet_from_user_id\":14431640,\"tweet_from_user\":\"timothykephart\",\"tweet_profile_image_url\":\"http:\\/\\/a3.twimg.com\\/profile_images\\/282590443\\/test_normal.jpg\",\"tweet_created_at\":\"2010-07-26 17:49:36\",\"tweet_text\":\"RT @shiftb: whoa, just found an awesome A\\/B test framework for rails <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/vanity.labnotes.org\\/<\\/a> anyone used it before?@ChronoPositron\"},{\"tweet_id\":\"19587439664\",\"tweet_from_user_id\":785148,\"tweet_from_user\":\"shiftb\",\"tweet_profile_image_url\":\"http:\\/\\/a3.twimg.com\\/profile_images\\/555784839\\/brandon_icon_normal.jpg\",\"tweet_created_at\":\"2010-07-26 16:52:19\",\"tweet_text\":\"whoa, just found an awesome A\\/B test framework for rails <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/vanity.labnotes.org\\/<\\/a> anyone used it before? #ExperimentDrivenDevelopment\"},{\"tweet_id\":\"18165123178\",\"tweet_from_user_id\":56644919,\"tweet_from_user\":\"readelicious\",\"tweet_profile_image_url\":\"http:\\/\\/a1.twimg.com\\/profile_images\\/312871002\\/delicious_normal.gif\",\"tweet_created_at\":\"2010-07-10 02:24:44\",\"tweet_text\":\"Vanity \\u2014 Welcome to Vanity <a href=\\\"http:\\/\\/vanity.labnotes.org\\/index.html\\\">http:\\/\\/goo.gl\\/fb\\/e0zLd<\\/a> #analytics #metrics\"},{\"tweet_id\":\"18144555877\",\"tweet_from_user_id\":2367111,\"tweet_from_user\":\"assaf\",\"tweet_profile_image_url\":\"http:\\/\\/a1.twimg.com\\/profile_images\\/30105312\\/profile-photo_normal.jpg\",\"tweet_created_at\":\"2010-07-09 20:11:50\",\"tweet_text\":\"@deepthawtz like this? <a href=\\\"http:\\/\\/vanity.labnotes.org\\/metrics.html\\\">http:\\/\\/vanity.labnotes.org\\/metrics.html<\\/a>\"},{\"tweet_id\":\"18027007347\",\"tweet_from_user_id\":15568945,\"tweet_from_user\":\"bermonpainter\",\"tweet_profile_image_url\":\"http:\\/\\/a3.twimg.com\\/profile_images\\/490420671\\/me_normal.jpg\",\"tweet_created_at\":\"2010-07-08 11:15:43\",\"tweet_text\":\"Checking out Vanity for some easy A\\/B testing for our apps. <a href=\\\"http:\\/\\/vanity.labnotes.org\\/\\\">http:\\/\\/vanity.labnotes.org\\/<\\/a> #rails #doublecompleterainbow T.T\"}]}"
26
25
  http_version: "1.1"
26
+ body: |-
27
+ { "totalresults": "2",
28
+ "startindex": 1,
29
+ "itemsperpage": 3,
30
+ "tweets": [
31
+ { "tweet_id": "20959239143",
32
+ "tweet_from_user_id": 1501751,
33
+ "tweet_from_user": "dude",
34
+ "tweet_profile_image_url": "http://a0.twimg.com/profile_images/305156692/ls_3001_author30_normal.jpg",
35
+ "tweet_created_at": "2010-08-12 08:30:04",
36
+ "tweet_text": "Super awesome <a href=\"http://vanity.labnotes.org/\">http://j.mp/aOrUnsz</a>" }
37
+ ]
38
+ }
27
39
  - !ruby/struct:VCR::HTTPInteraction
28
40
  request: !ruby/struct:VCR::Request
29
41
  method: :get
@@ -37,7 +49,7 @@
37
49
  content-type:
38
50
  - application/json; charset=utf-8
39
51
  body: |-
40
- { "totalresults": "11",
52
+ { "totalresults": "13",
41
53
  "startindex": 1,
42
54
  "itemsperpage": 3,
43
55
  "tweets": [
@@ -46,7 +58,7 @@
46
58
  "tweet_from_user": "assaf",
47
59
  "tweet_profile_image_url": "http://twitter.com/account/profile_image/assaf",
48
60
  "tweet_created_at": "2010-08-22 05:00:04",
49
- "tweet_text": "Super awesome <a href=\"http://vanity.labnotes.org/\">http://j.mp/aOrUnsz</a>" },
61
+ "tweet_text": "The last of its kind" },
50
62
  { "tweet_id": "20959239200",
51
63
  "tweet_from_user_id": 2367111,
52
64
  "tweet_from_user": "assaf",
@@ -55,9 +67,9 @@
55
67
  "tweet_text": "Not as awesome" },
56
68
  { "tweet_id": "20959239143",
57
69
  "tweet_from_user_id": 1501751,
58
- "tweet_from_user": "olivM",
70
+ "tweet_from_user": "dude",
59
71
  "tweet_profile_image_url": "http://a0.twimg.com/profile_images/305156692/ls_3001_author30_normal.jpg",
60
72
  "tweet_created_at": "2010-08-12 08:30:04",
61
- "tweet_text": "Vanity : an Experiment Driven Development framework for Rails : <a href=\"http://vanity.labnotes.org/\">http://j.mp/aOrUnsz</a> #AB_testing" }
73
+ "tweet_text": "Super awesome <a href=\"http://vanity.labnotes.org/\">http://j.mp/aOrUnsz</a>" }
62
74
  ]
63
75
  }
@@ -16,11 +16,11 @@ test DashFu::Mario::GithubIssues do
16
16
  end
17
17
 
18
18
  should "capture open issues" do
19
- assert subject.columns.include?(:id=>"open", :label=>"Open issues")
19
+ assert subject.columns.include?(id: "open", label: "Open issues")
20
20
  end
21
21
 
22
22
  should "capture closed issues" do
23
- assert subject.columns.include?(:id=>"closed", :label=>"Closed issues")
23
+ assert subject.columns.include?(id: "closed", label: "Closed issues")
24
24
  end
25
25
  end
26
26
  end
@@ -51,30 +51,30 @@ test DashFu::Mario::GithubIssues do
51
51
  setup { source.setup "repo"=>"assaf/vanity" }
52
52
 
53
53
  should "handle 404" do
54
- stub_request(:get, interactions.first.uri).to_return :status=>404
55
- stub_request(:get, interactions.second.uri).to_return :status=>404
56
- assert_raise(RuntimeError) { source.update }
54
+ stub_request(:get, interactions.first.uri).to_return status: 404
55
+ stub_request(:get, interactions.second.uri).to_return status: 404
56
+ source.update
57
57
  assert_equal "Could not find the repository assaf/vanity", source.last_error
58
58
  end
59
59
 
60
60
  should "handle 401" do
61
- stub_request(:get, interactions.first.uri).to_return :status=>401
62
- stub_request(:get, interactions.second.uri).to_return :status=>401
63
- assert_raise(RuntimeError) { source.update }
61
+ stub_request(:get, interactions.first.uri).to_return status: 401
62
+ stub_request(:get, interactions.second.uri).to_return status: 401
63
+ source.update
64
64
  assert_equal "You are not authorized to access this repository, or invalid username/password", source.last_error
65
65
  end
66
66
 
67
67
  should "handle other error" do
68
- stub_request(:get, interactions.first.uri).to_return :status=>500
69
- stub_request(:get, interactions.second.uri).to_return :status=>500
70
- assert_raise(RuntimeError) { source.update }
68
+ stub_request(:get, interactions.first.uri).to_return status: 500
69
+ stub_request(:get, interactions.second.uri).to_return status: 500
70
+ source.update
71
71
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
72
72
  end
73
73
 
74
74
  should "handle invlid document entity" do
75
- stub_request(:get, interactions.first.uri).to_return :body=>"Not JSON"
76
- stub_request(:get, interactions.last.uri).to_return :body=>"Not JSON"
77
- assert_raise(RuntimeError) { source.update }
75
+ stub_request(:get, interactions.first.uri).to_return body: "Not JSON"
76
+ stub_request(:get, interactions.last.uri).to_return body: "Not JSON"
77
+ source.update
78
78
  assert_equal "Last request didn't go as expected, trying again later", source.last_error
79
79
  end
80
80
 
@@ -88,98 +88,98 @@ test DashFu::Mario::GithubIssues do
88
88
  assert_equal 12, source.metric.values[:closed]
89
89
  end
90
90
 
91
- should "not create any activity" do
92
- source.update
93
- assert source.activities.empty?
94
- end
95
91
 
96
- context "repeating" do
97
- setup do
98
- source.update
99
- open = interactions.select { |i| i.uri =~ /open/ }
100
- stub_request(:get, open.first.uri).to_return :body=>open.last.response.body
101
- closed = interactions.select { |i| i.uri =~ /closed/ }
102
- stub_request(:get, closed.first.uri).to_return :body=>closed.last.response.body
103
- source.update
104
- end
92
+ context "activity for open issue" do
93
+ setup { source.update }
94
+ subject { source.activities.first }
105
95
 
106
- should "update open count" do
107
- assert_equal 2, source.metric.values[:open]
96
+ should "capture issue URL" do
97
+ assert_equal "http://github.com/assaf/vanity/issues#issue/21", subject.url
108
98
  end
109
99
 
110
- should "update closed count" do
111
- assert_equal 2, source.metric.values[:closed]
100
+ should "use SHA1 for ID" do
101
+ assert_match /^[0-9a-f]{40}$/, subject.uid
112
102
  end
113
103
 
114
- should "create activity for each issue opened or closed" do
115
- assert_equal 2, source.activities.count
104
+ should "capture issue creation time" do
105
+ assert_equal Time.parse("2010/08/19 19:59:31 UTC"), subject.timestamp
116
106
  end
117
107
 
118
- context "activity for open issue" do
119
- subject { source.activities.first }
108
+ should "capture issue title" do
109
+ assert_equal <<-HTML, subject.html
110
+ opened <a href="http://github.com/assaf/vanity/issues#issue/21">issue 21</a> on assaf/vanity:
111
+ <blockquote>Vanity 1.4.0 seems to have issues with Bundler</blockquote>
112
+ HTML
113
+ end
120
114
 
121
- should "capture issue URL" do
122
- assert_equal "http://github.com/assaf/vanity/issues#issue/22", subject.url
123
- end
115
+ should "tag as issue and open" do
116
+ assert_contains subject.tags, "issue"
117
+ assert_contains subject.tags, "opened"
118
+ end
124
119
 
125
- should "use SHA1 for ID" do
126
- assert_match /^[0-9a-f]{40}$/, subject.uid
127
- end
120
+ should "be valid" do
121
+ assert subject.valid?
122
+ end
123
+ end
128
124
 
129
- should "capture issue creation time" do
130
- assert_equal Time.parse("2010/03/17 22:32:02 UTC"), subject.timestamp
131
- end
125
+ context "activity for closed issue" do
126
+ setup { source.update }
127
+ subject { source.activities.last }
132
128
 
133
- should "capture issue title" do
134
- assert_equal <<-HTML, subject.html
135
- opened <a href="http://github.com/assaf/vanity/issues#issue/22">issue 22</a> on assaf/vanity:
136
- <blockquote>Option to use Google Analytics for A/B testing</blockquote>
137
- HTML
138
- end
129
+ should "capture issue URL" do
130
+ assert_equal "http://github.com/assaf/vanity/issues#issue/18", subject.url
131
+ end
139
132
 
140
- should "tag as issue and open" do
141
- assert_contains subject.tags, "issue"
142
- assert_contains subject.tags, "opened"
143
- end
133
+ should "use SHA1 for ID" do
134
+ assert_match /^[0-9a-f]{40}$/, subject.uid
135
+ end
144
136
 
145
- should "be valid" do
146
- assert subject.valid?
147
- end
137
+ should "capture issue closing time" do
138
+ assert_equal Time.parse("2010/07/03 02:16:42 UTC"), subject.timestamp
148
139
  end
149
140
 
150
- context "activity for closed issue" do
151
- subject { source.activities.last }
141
+ should "capture issue title" do
142
+ assert_equal <<-HTML, subject.html
143
+ closed <a href="http://github.com/assaf/vanity/issues#issue/18">issue 18</a> on assaf/vanity:
144
+ <blockquote>Passwords not supported for the Redis config</blockquote>
145
+ HTML
146
+ end
152
147
 
153
- should "capture issue URL" do
154
- assert_equal "http://github.com/assaf/vanity/issues#issue/19", subject.url
155
- end
148
+ should "tag as issue and closed" do
149
+ assert_contains subject.tags, "issue"
150
+ assert_contains subject.tags, "closed"
151
+ end
156
152
 
157
- should "use SHA1 for ID" do
158
- assert_match /^[0-9a-f]{40}$/, subject.uid
159
- end
153
+ should "be valid" do
154
+ assert subject.valid?
155
+ end
156
+ end
160
157
 
161
- should "capture issue closing time" do
162
- assert_equal Time.parse("2010/07/03 04:16:42 UTC"), subject.timestamp
163
- end
164
158
 
165
- should "capture issue title" do
166
- assert_equal <<-HTML, subject.html
167
- closed <a href="http://github.com/assaf/vanity/issues#issue/19">issue 19</a> on assaf/vanity:
168
- <blockquote>Passwords not supported for the Redis config</blockquote>
169
- HTML
170
- end
159
+ context "repeating" do
160
+ setup do
161
+ source.update
162
+ source.activities.clear
163
+ open = interactions.select { |i| i.uri =~ /open/ }
164
+ stub_request(:get, open.first.uri).to_return body: open.last.response.body
165
+ closed = interactions.select { |i| i.uri =~ /closed/ }
166
+ stub_request(:get, closed.first.uri).to_return body: closed.last.response.body
167
+ source.update
168
+ end
171
169
 
172
- should "tag as issue and closed" do
173
- assert_contains subject.tags, "issue"
174
- assert_contains subject.tags, "closed"
175
- end
170
+ should "update open count" do
171
+ assert_equal 2, source.metric.values[:open]
172
+ end
176
173
 
177
- should "be valid" do
178
- assert subject.valid?
179
- end
174
+ should "update closed count" do
175
+ assert_equal 2, source.metric.values[:closed]
180
176
  end
181
177
 
178
+ should "create activity for each issue opened or closed" do
179
+ assert_equal 2, source.activities.count
180
+ end
182
181
  end
182
+
183
183
  end
184
184
 
185
185
 
@@ -188,7 +188,7 @@ closed <a href="http://github.com/assaf/vanity/issues#issue/19">issue 19</a> on
188
188
  subject { source.meta }
189
189
 
190
190
  should "link to repository" do
191
- assert_contains subject, :title=>"On Github", :url=>"http://github.com/assaf/vanity/issues"
191
+ assert_contains subject, title: "On Github", url: "http://github.com/assaf/vanity/issues"
192
192
  end
193
193
  end
194
194
  end