Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Commit ef99631

Browse files
committed
Add sorting of doc_methods on a repo by documentation status
This commit adds sorting on a repo between documented and undocumented methods, via a simple UI. Closes #21.
1 parent f1057f7 commit ef99631

File tree

10 files changed

+88
-3
lines changed

10 files changed

+88
-3
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ end
5757

5858
group :test do
5959
gem 'mocha', require: false
60+
gem 'capybara', '2.3.0'
61+
gem 'launchy'
6062
end
6163

6264
gem 'devise', "~> 3.2.2"

Gemfile.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@ GEM
2727
minitest (~> 5.1)
2828
thread_safe (~> 0.1)
2929
tzinfo (~> 1.1)
30+
addressable (2.3.8)
3031
arel (5.0.1.20140414130214)
3132
bcrypt-ruby (3.1.2)
3233
bluecloth (2.2.0)
3334
builder (3.2.2)
35+
capybara (2.3.0)
36+
mime-types (>= 1.16)
37+
nokogiri (>= 1.3.3)
38+
rack (>= 1.0.0)
39+
rack-test (>= 0.5.4)
40+
xpath (~> 2.0)
3441
coffee-rails (4.0.0)
3542
coffee-script (>= 2.2.0)
3643
railties (>= 4.0.0.beta, < 5.0)
@@ -77,6 +84,8 @@ GEM
7784
multi_json (>= 1.5)
7885
kgio (2.9.3)
7986
kramdown (1.1.0)
87+
launchy (2.4.3)
88+
addressable (~> 2.3)
8089
mail (2.5.4)
8190
mime-types (~> 1.16)
8291
treetop (~> 1.4.8)
@@ -87,13 +96,16 @@ GEM
8796
rails (> 3.2.0)
8897
metaclass (0.0.4)
8998
mime-types (1.25.1)
99+
mini_portile (0.6.2)
90100
minitest (5.3.3)
91101
mocha (1.0.0)
92102
metaclass (~> 0.0.1)
93103
mono_logger (1.1.0)
94104
multi_json (1.10.0)
95105
multi_xml (0.5.4)
96106
multipart-post (1.2.0)
107+
nokogiri (1.6.6.2)
108+
mini_portile (~> 0.6.0)
97109
oauth2 (0.8.1)
98110
faraday (~> 0.8)
99111
httpauth (~> 0.1)
@@ -206,13 +218,16 @@ GEM
206218
activesupport (>= 3.0.7)
207219
rails (>= 3.0.7)
208220
will_paginate (3.0.4)
221+
xpath (2.0.0)
222+
nokogiri (~> 1.3)
209223
yard (0.8.7.3)
210224

211225
PLATFORMS
212226
ruby
213227

214228
DEPENDENCIES
215229
bluecloth
230+
capybara (= 2.3.0)
216231
coffee-rails (~> 4.0.0)
217232
dalli
218233
devise (~> 3.2.2)
@@ -222,6 +237,7 @@ DEPENDENCIES
222237
httparty
223238
jbuilder (~> 1.0.1)
224239
jquery-rails
240+
launchy
225241
mail_view (~> 1.0.2)
226242
maildown
227243
mocha

app/controllers/repos_controller.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ def new
2727
end
2828

2929
def show
30-
@repo = Repo.where(full_name: params[:full_name]).first
30+
@repo = Repo.where(full_name: params[:full_name]).first
3131

3232
if @repo
33-
@docs = @repo.doc_methods.order("created_at DESC").page(params[:page]).per_page(params[:per_page]||20)
33+
@docs = @repo
34+
.doc_methods
35+
.send(params[:doc_status] || :scoper)
36+
.order("created_at DESC")
37+
.page(params[:page])
38+
.per_page(params[:per_page]||20)
39+
3440
@repo_sub = current_user.repo_subscriptions.where(repo_id: @repo.id).first if current_user
3541
@subscribers = @repo.
3642
subscribers.

app/models/doc_method.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def self.with_docs
1818
where("doc_comments_count > 0")
1919
end
2020

21+
def self.scoper
22+
where(nil)
23+
end
24+
2125
def raw_file
2226
read_attribute(:file)
2327
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def self.find_for_github_oauth(auth, signed_in_resource=nil)
9393
user.update_attributes(params)
9494
else
9595
email = auth.info.email
96-
email = GitHubBub::Request.fetch("/user/emails", token: token).json_body.first if email.blank?
96+
email = GitHubBub.get("/user/emails", token: token).json_body.first if email.blank?
9797
params = params.merge(:password => Devise.friendly_token[0,20],
9898
:name => auth.extra.raw_info.name,
9999
:email => email)

app/views/repos/show.html.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080
<hr />
8181
<%= will_paginate @docs, :container => false %>
8282

83+
<ul class='nav nav-tabs'>
84+
<li class=<%= 'active' if params[:doc_status] == 'with_docs' %>>
85+
<%= link_to 'Documented Methods', repo_path(@repo, doc_status: 'with_docs') %>
86+
</li>
87+
<li class=<%= 'active' if params[:doc_status] == 'missing_docs' %>>
88+
<%= link_to 'Undocumented Methods', repo_path(@repo, doc_status: 'missing_docs') %>
89+
</li>
90+
</ul>
91+
8392
<ul>
8493
<% @docs.each do |doc| %>
8594
<li>

test/fixtures/doc_comments.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
comment:
2+
id: 1
3+
doc_class_id: 1
4+
doc_method_id: 2
5+
comment: 'this is a comment'
6+
created_at: 2012-11-10 21:50:48.351554000 Z
7+
updated_at: 2012-11-10 21:50:48.351554000 Z

test/fixtures/doc_methods.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
migrate:
2+
id: 1
3+
repo_id: 3
4+
name: undocumented_method
5+
line: 43
6+
created_at: 2012-11-10 21:50:48.351554000 Z
7+
updated_at: 2012-11-10 21:50:48.351554000 Z
8+
doc_comments_count: 0
9+
path: 'lib/sinatra'
10+
file: 'base.rb'
11+
12+
other:
13+
id: 2
14+
repo_id: 3
15+
name: documented_method
16+
line: 43
17+
created_at: 2012-11-10 21:50:48.351554000 Z
18+
updated_at: 2012-11-10 21:50:48.351554000 Z
19+
doc_comments_count: 100
20+
path: 'lib/sinatra'
21+
file: 'base.rb'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require "test_helper"
2+
3+
class SortingMethodsTest < ActionDispatch::IntegrationTest
4+
include Capybara::DSL
5+
fixtures :repos
6+
fixtures :doc_methods
7+
fixtures :doc_comments
8+
9+
test 'sorting methods by documentation status' do
10+
visit '/'
11+
click_link 'rails'
12+
click_link 'Documented Methods'
13+
assert_not page.has_content?('ActiveRecord#undocumented')
14+
click_link 'Undocumented Methods'
15+
assert_not page.has_content?('ActiveRecord#documented')
16+
end
17+
18+
end

test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ def fixture_path(name = "")
2121

2222
require 'parsers/yard_test'
2323
require 'mocha/setup'
24+
require 'capybara/rails'
2425

2526
Q.queue_config.inline = true
27+

0 commit comments

Comments
 (0)