Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add presenter for language info pages - Add route for languages info pages - Add view for language info pages - Change links in language menu to language info pages - Add test suite for presenter - Fix error in routes - Make tests pass for track_problems - Edit tracks_test.rb so that it tests methods fom sample data and not pull from API, which were making the tests fail when tracks_test.rb was run on its own. - Add template for individual language landing pages. - Debug route, add to routes file - Add route for language template page to lib/app/route.rb and lib/app.rb - Catch fake language exception - Add styling to language info page - Create problems_test.rb file. - Remove commented out initialize method for class - Remove extra lines from languages_test.rb - Add tests and relevant files for track_id and track_problems. - Add require_relative '../../api_helper.rb', require_relative '../../app_helper.rb' and include DBCleaner to test/app/presenters/problems_test.rb - Remove extra spaces from languages.rb - Change wording for track_problems test - Add links to problem READMEs from language info page - Add test for fetch_all_problems method in problems presenter. - Remove commented out method and test. - Remove old routes debugging - Remove blank space in routes/languages.rb - Remove blank space in routes.rb - Remove duplication in routes
- Loading branch information
Showing
15 changed files
with
1,917 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'json' | ||
|
||
module ExercismWeb | ||
module Presenters | ||
module Special | ||
class Problem < OpenStruct | ||
end | ||
|
||
class Problems | ||
def initialize(track_id) | ||
@track_id = track_id | ||
end | ||
|
||
def track_id | ||
@track_id | ||
end | ||
|
||
def all_problems | ||
@all_problems ||= fetch_all_problems | ||
end | ||
|
||
def track_problems | ||
@track_problems ||= problems_hash | ||
end | ||
|
||
def fetch_all_problems | ||
status, body = Xapi.get("problems") | ||
if status != 200 | ||
raise "something fishy in x-api: (#{status}) - #{body}" | ||
end | ||
JSON.parse(body)["problems"] | ||
end | ||
|
||
def problems_hash | ||
@track_problems = [] | ||
all_problems.each do |problem| | ||
slug = problem["slug"] | ||
if problem["track_ids"].include?(track_id) | ||
@track_problems << { | ||
:slug => slug, | ||
:blurb => problem["blurb"], | ||
:name => slug.split('-').map(&:capitalize).join(' ') | ||
} | ||
end | ||
end | ||
@track_problems.map {|problem| Problem.new(problem)} | ||
end | ||
end | ||
end | ||
end | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ class Account < Core | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'app/presenters/problems' | ||
|
||
module ExercismWeb | ||
module Routes | ||
class Languages < Core | ||
get '/languages/:track_id' do |track_id| | ||
begin | ||
active = ExercismWeb::Presenters::Tracks.find(track_id.to_s).active? | ||
exists = true | ||
rescue Exception => e | ||
Bugsnag.notify(e) | ||
"#{track_id} is not a language" | ||
exists = false | ||
end | ||
|
||
locals = { | ||
problems: Presenters::Special::Problems.new(track_id).track_problems, | ||
language: Language.of(track_id), | ||
slug: track_id, | ||
active: active, | ||
exists: exists | ||
} | ||
erb :"languages/languages", locals: locals | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div class="container getting-started"> | ||
<section class="page-header"> | ||
<h1><%= language %></h1> | ||
</section> | ||
<% if active %> | ||
<article class="article-block"> | ||
<div class="article-contents"> | ||
<h2 class="header">Available Exercises</h2> | ||
<% problems.each do |problem| %> | ||
<h5><a href="/exercises/<%= slug %>/<%= problem.slug %>/readme"><%= problem.name %></a></h5> | ||
<p><%= problem.blurb %></p> | ||
<% end %> | ||
</div> | ||
</article> | ||
<article class="article-block"> | ||
<div class="article-contents"> | ||
<h2 class="header">Getting Started</h2> | ||
<p>Need help getting started? You can find install documentation and resources for <%= language %> <a href="http://help.exercism.io/getting-started-with-<%= slug %>.html">here</a>.</p> | ||
</div> | ||
</article> | ||
<% elsif exists %> | ||
<h3>We're still working on <%= language %>. <a href="https://github.com/exercism/x<%= slug %>">Want to help us out?</a></h3> | ||
<% else %> | ||
<h3>If you'd like to see exercises in this language, <a href="https://github.com/exercism/exercism.io/issues/new">let us know.</a></h3> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ def language | |
def in?(other_track_id) | ||
track_id == other_track_id | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require_relative '../../test_helper' | ||
require_relative '../../app_presenters_helper' | ||
require_relative '../../api_helper' | ||
require 'mocha/setup' | ||
require 'app/presenters/problems' | ||
require_relative '../../api_helper.rb' | ||
require_relative '../../app_helper.rb' | ||
|
||
class PresentersProblemsTest < Minitest::Test | ||
include Rack::Test::Methods | ||
include DBCleaner | ||
|
||
def app | ||
ExercismWeb::App | ||
end | ||
|
||
def test_knows_its_track_id | ||
track = ExercismWeb::Presenters::Special::Problems.new("ruby") | ||
assert_equal "ruby", track.track_id | ||
end | ||
|
||
def all_problems_json | ||
File.read("./test/fixtures/approvals/api_all_problems.approved.json") | ||
end | ||
|
||
def test_that_fetch_all_problems_can_get_all_problems | ||
Xapi.stub(:get, [200, all_problems_json]) do | ||
get '/problems' | ||
problems = ExercismWeb::Presenters::Special::Problems.new('ruby') | ||
assert_includes problems.fetch_all_problems.to_s, '"slug"=>"zipper"' | ||
end | ||
end | ||
|
||
def test_can_return_problems_for_specific_track | ||
Xapi.stub(:get, [200, all_problems_json]) do | ||
get '/languages/ruby' | ||
problems = ExercismWeb::Presenters::Special::Problems.new('ruby') | ||
assert_includes problems.track_problems.to_s, "Write a program that implements a binary search algorithm." | ||
end | ||
end | ||
|
||
def test_does_not_return_problems_not_in_specific_track | ||
Xapi.stub(:get, [200, all_problems_json]) do | ||
get '/languages/ruby' | ||
problems = ExercismWeb::Presenters::Special::Problems.new('ruby') | ||
refute_includes problems.track_problems.to_s, "Compute the result for a game of Hex / Polygon" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module AppPresentersHelper | ||
def all_problems_json | ||
problems_file = File.expand_path('../fixtures/approvals/api_all_problems.approved.json', __FILE__) | ||
File.read(problems_file) | ||
end | ||
|
||
def ruby_track_problems_array | ||
array_file = File.expand_path('../fixtures/approvals/ruby_track_problems.approved.txt', __FILE__) | ||
File.read(array_file) | ||
end | ||
end |
Oops, something went wrong.