Skip to content

Commit

Permalink
Display all hanami contributors on index page
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Mar 20, 2017
1 parent 12cb5e7 commit cd66765
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/web/config/routes.rb
Expand Up @@ -3,4 +3,4 @@
#
# Example:
# get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
get '/contributors', to: 'contributors#index'
root to: 'contributors#index'
2 changes: 2 additions & 0 deletions apps/web/controllers/contributors/index.rb
@@ -1,8 +1,10 @@
module Web::Controllers::Contributors
class Index
include Web::Action
expose :contributors

def call(params)
@contributors = ContributorRepository.new.all
end
end
end
4 changes: 4 additions & 0 deletions apps/web/templates/contributors/index.html.slim
@@ -0,0 +1,4 @@
- contributors.each do |contributor|
.contributor
.contributor__github = link_to_github(contributor)

4 changes: 4 additions & 0 deletions apps/web/views/contributors/index.rb
@@ -1,5 +1,9 @@
module Web::Views::Contributors
class Index
include Web::View

def link_to_github(contributor)
link_to contributor.github, "https://github.com/#{contributor.github}"
end
end
end
20 changes: 17 additions & 3 deletions spec/web/controllers/contributors/index_spec.rb
Expand Up @@ -3,9 +3,23 @@
RSpec.describe Web::Controllers::Contributors::Index do
let(:action) { described_class.new }
let(:params) { Hash[] }
let(:repo) { ContributorRepository.new }

it 'is successful' do
response = action.call(params)
expect(response[0]).to eq 200
it { expect(action.call(params)).to be_success }

describe 'expose' do
describe '#contributors' do
before do
3.times { |i| repo.create(github: "davydovanton##{i}") }
action.call(params)
end

after { repo.clear }

it 'returns all tasks' do
expect(action.contributors).to all(be_a(Contributor))
expect(action.contributors.count).to eq 3
end
end
end
end
9 changes: 5 additions & 4 deletions spec/web/views/contributors/index_spec.rb
Expand Up @@ -6,10 +6,11 @@
let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render }

it 'exposes #foo' do
pending 'This is an auto-generated test. Edit it and add your own tests.'
describe '#link_to_github' do
let(:contributor) { Contributor.new(github: 'davydovanton') }

# Example
expect(view.foo).to eq exposures.fetch(:foo)
it 'returns link to contributor github' do
expect(view.link_to_github(contributor).to_s).to eq '<a href="https://github.com/davydovanton">davydovanton</a>'
end
end
end

0 comments on commit cd66765

Please sign in to comment.