Skip to content

Commit

Permalink
Rework routes
Browse files Browse the repository at this point in the history
  • Loading branch information
rwojsznis committed Mar 6, 2018
1 parent 89ceb62 commit e67d80f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
10 changes: 9 additions & 1 deletion lib/sidekiq/expected_failures/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def link_to_details(job)
json(failures: Sidekiq::ExpectedFailures.counters)
end

app.get "/expected_failures" do
panel = proc do
@dates = Sidekiq::ExpectedFailures.dates
@count = (params[:count] || 50).to_i

Expand All @@ -41,6 +41,14 @@ def link_to_details(job)

erb File.read(File.join(web_dir, "views/expected_failures.erb"))
end

app.get "/expected_failures/day/:date" do
self.instance_exec(&panel)
end

app.get "/expected_failures" do
self.instance_exec(&panel)
end
end
end
end
Expand Down
18 changes: 17 additions & 1 deletion test/lib/web_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_sample_failure

after { Timecop.return }

it 'can display home with expected failures llink' do
it 'can display home with expected failures link' do
get '/'
last_response.status.must_equal(200)
last_response.body.must_include('<a href="/expected_failures">Expected Failures</a>')
Expand Down Expand Up @@ -161,5 +161,21 @@ def create_sample_failure
end
end
end

describe 'pagination & filtering' do
before do
51.times { create_sample_failure }
end

it 'displays pagination widget when needed' do
get '/expected_failures'
last_response.body.must_include('<ul class="pagination')
end

it 'properly links to next page' do
get '/expected_failures/day/2013-09-10'
last_response.body.must_include('/expected_failures/day/2013-09-10?page=2')
end
end
end
end
6 changes: 5 additions & 1 deletion web/assets/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
e.preventDefault();
});

$('#filter-jobs select, #clear-jobs select').live('change', function(e){
$('#clear-jobs select').live('change', function(e){
$(this).parent('form').submit();
});

$('#filter-jobs select').live('change', function(e){
location.href = $(this).val();
});
});
6 changes: 3 additions & 3 deletions web/views/expected_failures.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@
<label>Choose date:</label>
<select name="date">
<% @dates.each do |date, count| %>
<option value="<%= date %>" <%= "selected" if date == @date %>><%= date %> (<%= count %>)</option>
<option value="<%= "#{root_path}expected_failures/day/#{date}" %>" <%= "selected" if date == @date %>><%= date %> (<%= count %>)</option>
<% end %>
</select>
</form>

<p class="clearfix"></p>

<%= erb :_paging, locals: { url: "#{root_path}expected_failures?date=#{@date}" } %>
<%= erb :_paging, locals: { url: "#{root_path}expected_failures/day/#{@date}" } %>

<table id="expected" class="queues table table-hover table-bordered table-striped table-white">
<thead>
Expand All @@ -105,7 +105,7 @@
<% end %>
</table>

<%= erb :_paging, locals: { url: "#{root_path}expected_failures/#{@date}" } %>
<%= erb :_paging, locals: { url: "#{root_path}expected_failures/day/#{@date}" } %>
<% else %>
<p class="clearfix"></p>
Expand Down

0 comments on commit e67d80f

Please sign in to comment.