problem_child 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e83ecc3d971edca9afa09d88616214477ad6674
4
- data.tar.gz: 2a7a552a65d5457ec6d2008e647226e18f7a050f
3
+ metadata.gz: 054ff3ece80e2d56567e0852631eb17406a13935
4
+ data.tar.gz: f943642e28dd13536bf7daab9cd950fe7a258249
5
5
  SHA512:
6
- metadata.gz: 17b494db5c8b46d04004377e62845dc8ba1cfffbeb004331acb9d1cf119a061d1bd4c8330bc798d5b4b4f122ebbd7bb053c691e94ed25ee6766936d4628abdbe
7
- data.tar.gz: ebd5fecb4ed6e22c5522d678fdafc6ba5fd332849f8abdf7121ccc333d4364a9499aec40069c74ba5fbdf75f4e2906db7fb9775e9bcec9951765d12b92660187
6
+ metadata.gz: 3f62815854bd1f1fc0dee735893056ecd60fb683e33865c44393f581f6dc1972336b3a98bf861acb87abab73ca828ab395a3b08431e4c309f46734abcbe97df3
7
+ data.tar.gz: 1152a305b0aa0a5c1e0b92396f16541a9065b097df335ad8695b2fe09b16c86f14df5fbd5d07d672c61f3eef8fa83736a914854ca8851f3fb76f190c77f3971e
data/lib/problem_child.rb CHANGED
@@ -57,13 +57,15 @@ module ProblemChild
57
57
 
58
58
  get "/" do
59
59
  if session[:form_data]
60
- flash = :success if create_issue
60
+ issue = create_issue
61
61
  session[:form_data] = nil
62
+ access = repo_access?
62
63
  else
63
- flash = nil
64
+ issue = nil
65
+ access = false
64
66
  auth!
65
67
  end
66
- halt erb :form, :layout => :layout, :locals => { :repo => repo, :anonymous => anonymous_submissions?, :flash => flash }
68
+ halt erb :form, :layout => :layout, :locals => { :repo => repo, :anonymous => anonymous_submissions?, :issue => issue, :access => access }
67
69
  end
68
70
 
69
71
  post "/" do
@@ -35,7 +35,15 @@ module ProblemChild
35
35
  end
36
36
 
37
37
  def create_issue
38
- client.create_issue(repo, form_data["title"], issue_body)
38
+ issue = client.create_issue(repo, form_data["title"], issue_body)
39
+ issue["number"] if issue
40
+ end
41
+
42
+ def repo_access?
43
+ return true unless anonymous_submissions?
44
+ !client.repository(repo)["private"]
45
+ rescue
46
+ false
39
47
  end
40
48
 
41
49
  def auth!
@@ -1,3 +1,3 @@
1
1
  module ProblemChild
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -5,8 +5,10 @@
5
5
  <% end %>
6
6
  </h1>
7
7
 
8
- <% if flash && flash == :success %>
9
- <div class="alert alert-success" role="alert">Your issue was successfully submitted.</div>
8
+ <% if issue %>
9
+ <div class="alert alert-success" role="alert">
10
+ Your issue was successfully submitted<% if access %> as <a href="http://github.com/<%= repo %>/issues/<%= issue %>"><%= repo %>#<%= issue %></a><% end %>.
11
+ </div>
10
12
  <% end %>
11
13
 
12
14
  <form method="post">
@@ -83,11 +83,44 @@ describe "ProblemChild::Helpers" do
83
83
 
84
84
  stub = stub_request(:post, "https://api.github.com/repos/benbalter/test-repo-ignore-me/issues").
85
85
  with(:body => "{\"labels\":[],\"title\":\"title\",\"body\":\"* **Foo**: bar\"}").
86
- to_return(:status => 200)
86
+ to_return(:status => 200, :body => '{"number": 1234}', :headers => { 'Content-Type' => 'application/json' })
87
87
 
88
- @helper.create_issue
88
+ expect(@helper.create_issue).to eql(1234)
89
89
  expect(stub).to have_been_requested
90
90
  end
91
91
  end
92
92
  end
93
+
94
+ it "knows auth'd users can access a repo" do
95
+ stub_request(:get, "https://api.github.com/repos/benbalter/test-repo-ignore-me").
96
+ to_return(:status => 200, :body => '{"private": true}', :headers => { 'Content-Type' => 'application/json' })
97
+
98
+ with_env "GITHUB_TOKEN", nil do
99
+ with_env "GITHUB_REPO", "benbalter/test-repo-ignore-me" do
100
+ expect(@helper.repo_access?).to eql(true)
101
+ end
102
+ end
103
+ end
104
+
105
+ it "knows anonymous users can access public repos" do
106
+ stub_request(:get, "https://api.github.com/repos/benbalter/test-repo-ignore-me").
107
+ to_return(:status => 200, :body => '{"private": false}', :headers => { 'Content-Type' => 'application/json' })
108
+
109
+ with_env "GITHUB_TOKEN", "1234" do
110
+ with_env "GITHUB_REPO", "benbalter/test-repo-ignore-me" do
111
+ expect(@helper.repo_access?).to eql(true)
112
+ end
113
+ end
114
+ end
115
+
116
+ it "knows anonymous users can't access private repos" do
117
+ stub_request(:get, "https://api.github.com/repos/benbalter/test-repo-ignore-me").
118
+ to_return(:status => 200, :body => '{"private": true}', :headers => { 'Content-Type' => 'application/json' })
119
+
120
+ with_env "GITHUB_TOKEN", "1234" do
121
+ with_env "GITHUB_REPO", "benbalter/test-repo-ignore-me" do
122
+ expect(@helper.repo_access?).to eql(false)
123
+ end
124
+ end
125
+ end
93
126
  end
@@ -86,13 +86,14 @@ describe "logged in user" do
86
86
 
87
87
  stub_request(:post, "https://api.github.com/repos/benbalter/test-repo-ignore-me/issues").
88
88
  with(:body => "{\"labels\":[],\"title\":\"title\",\"body\":\"* **Foo**: bar\"}").
89
- to_return(:status => 200)
89
+ to_return(:status => 200, :body => '{"number": 1234}', :headers => { 'Content-Type' => 'application/json' })
90
90
 
91
91
  post "/", :title => "title", :foo => "bar"
92
92
  follow_redirect!
93
93
 
94
94
  expect(last_response.status).to eql(200)
95
- expect(last_response.body).to match(/Your issue was successfully submitted/)
95
+ expected = '<a href="http://github.com/benbalter/test-repo-ignore-me/issues/1234">benbalter/test-repo-ignore-me#1234</a>'
96
+ expect(last_response.body).to match(expected)
96
97
  end
97
98
  end
98
99
  end
@@ -129,13 +130,16 @@ describe "logged out user" do
129
130
 
130
131
  stub_request(:post, "https://api.github.com/repos/benbalter/test-repo-ignore-me/issues").
131
132
  with(:body => "{\"labels\":[],\"title\":\"title\",\"body\":\"* **Foo**: bar\"}").
132
- to_return(:status => 200)
133
+ to_return(:status => 200, :body => '{"number": 1234}', :headers => { 'Content-Type' => 'application/json' })
134
+
135
+ stub_request(:get, "https://api.github.com/repos/benbalter/test-repo-ignore-me").
136
+ to_return(:status => 200, :body => '{"private": true}', :headers => { 'Content-Type' => 'application/json' })
133
137
 
134
138
  post "/", :title => "title", :foo => "bar"
135
139
  follow_redirect!
136
140
 
137
141
  expect(last_response.status).to eql(200)
138
- expect(last_response.body).to match(/Your issue was successfully submitted/)
142
+ expect(last_response.body).to match(/Your issue was successfully submitted\./)
139
143
  end
140
144
  end
141
145
  end
@@ -147,14 +151,16 @@ describe "logged out user" do
147
151
 
148
152
  stub_request(:post, "https://api.github.com/repos/benbalter/test-repo-ignore-me/issues").
149
153
  with(:body => "{\"labels\":[],\"title\":\"title\",\"body\":\"* **Foo**: #{long_string}\"}").
150
- to_return(:status => 200)
154
+ to_return(:status => 200, :body => '{"number": 1234}', :headers => { 'Content-Type' => 'application/json' })
151
155
 
156
+ stub_request(:get, "https://api.github.com/repos/benbalter/test-repo-ignore-me").
157
+ to_return(:status => 200, :body => '{"private": true}', :headers => { 'Content-Type' => 'application/json' })
152
158
 
153
159
  post "/", :title => "title", :foo => long_string
154
160
  follow_redirect!
155
161
 
156
162
  expect(last_response.status).to eql(200)
157
- expect(last_response.body).to match(/Your issue was successfully submitted/)
163
+ expect(last_response.body).to match(/Your issue was successfully submitted\./)
158
164
  end
159
165
  end
160
166
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: problem_child
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra