Permalink
Browse files

Add article show page

  • Loading branch information...
avdgaag committed Mar 24, 2015
1 parent bff69a6 commit e9342ff9f08ef1cb70139bc1aa39014958e7a110
@@ -6,3 +6,4 @@
# This route will look for `Web::Controllers::Home::Index` action in `apps/web/controllers/home/index.rb`.
# Please, uncomment the following line to have a working example.
get '/', to: 'home#index'
get '/articles/:id', to: 'articles#show'
@@ -0,0 +1,11 @@
module Web::Controllers::Articles
class Show
include Web::Action
expose :article
def call(params)
@article = Demo::ArticleRepository.find(params[:id])
end
end
end
@@ -0,0 +1,6 @@
<div class="article">
<h2 class="article__title"><%= article.title %></h2>
<div class="article__body">
<%= article.body %>
</div>
</div>
@@ -3,7 +3,7 @@
<% if articles.any? %>
<% articles.each do |article| %>
<div class="article">
<h3 class="article__title"><%= article.title %></h3>
<h3 class="article__title"><a href="/articles/<%= article.id %>" rel="permalink"><%= article.title %></a></h3>
<div clas="article__body">
<%= article.body %>
</div>
@@ -0,0 +1,5 @@
module Web::Views::Articles
class Show
include Web::View
end
end
@@ -0,0 +1,21 @@
require_relative '../../../spec_helper'
module Web::Controllers::Articles
describe Show do
let(:action) { Web::Controllers::Articles::Show.new }
let(:params) { Hash[id: 1] }
it 'is successful' do
response = action.call(params)
assert_equal 200, response[0], 'expected HTTP response 200'
end
it 'exposes article' do
article = Object.new
Demo::ArticleRepository.stub :find, article do
action.call(params)
end
assert_same article, action.exposures[:article], 'article object was not exposed'
end
end
end
@@ -0,0 +1,18 @@
require_relative '../../features_helper'
describe 'Article page' do
before do
Demo::ArticleRepository.clear
@article = Demo::ArticleRepository.create(
Demo::Article.new(title: 'Hello, world', body: 'Lorem ipsum')
)
end
it 'shows the title and body of the article' do
visit "/"
click_link 'Hello, world'
assert page.has_css?('.article'), 'expected a .article element'
assert page.has_css?('.article__title', text: 'Hello, world'), 'expected the article title'
assert page.has_css?('.article__body', text: 'Lorem ipsum'), 'expected the article body'
end
end
@@ -0,0 +1,13 @@
require_relative '../../../spec_helper'
module Web::Views::Articles
describe Show do
let(:exposures) { Hash[article: Object.new] }
let(:template) { Lotus::View::Template.new('apps/web/templates/articles/show.html.erb') }
let(:view) { Web::Views::Articles::Show.new(template, exposures) }
it "exposes #article" do
assert_same exposures[:article], view.article, 'view should have exposed article'
end
end
end

0 comments on commit e9342ff

Please sign in to comment.