Skip to content

Commit

Permalink
Add admin page to list all available projects in DB
Browse files Browse the repository at this point in the history
See #39
  • Loading branch information
Bounga committed Feb 8, 2018
1 parent b2cc14e commit fe8a439
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/admin/controllers/projects/index.rb
Expand Up @@ -2,7 +2,10 @@ module Admin::Controllers::Projects
class Index class Index
include Admin::Action include Admin::Action


expose :projects

def call(params) def call(params)
@projects = ProjectRepository.new.sorted
end end
end end
end end
4 changes: 3 additions & 1 deletion apps/admin/templates/application.html.slim
Expand Up @@ -4,5 +4,7 @@ html
title title
| Admin | Admin
= favicon = favicon
= stylesheet 'bootstrap', 'main'
body body
= yield .container
= yield
12 changes: 11 additions & 1 deletion apps/admin/templates/projects/index.html.slim
@@ -1 +1,11 @@
p Here will be all projects! h2 All projects

table.table.table-hover
tr
th Project name
th Since
- projects.each do |project|
tr
td = link_to_github(project)
td = project.created_at.strftime('%d %B %Y')

4 changes: 4 additions & 0 deletions apps/admin/views/projects/index.rb
@@ -1,5 +1,9 @@
module Admin::Views::Projects module Admin::Views::Projects
class Index class Index
include Admin::View include Admin::View

def link_to_github(project)
link_to project.name, "https://github.com/hanami/#{project.name}"
end
end end
end end
3 changes: 3 additions & 0 deletions lib/contributors/repositories/project_repository.rb
@@ -1,2 +1,5 @@
class ProjectRepository < Hanami::Repository class ProjectRepository < Hanami::Repository
def sorted
projects.order { name.asc }
end
end end
30 changes: 30 additions & 0 deletions spec/admin/controllers/projects/index_spec.rb
Expand Up @@ -6,4 +6,34 @@
response = action.call(params) response = action.call(params)
expect(response[0]).to eq 200 expect(response[0]).to eq 200
end end

describe 'expose' do
describe '#projects' do
context 'when db empty' do
before { action.call(params) }

it { expect(action.projects.to_a).to eq [] }
end

context 'when db has some projects' do
let(:project_repo) { ProjectRepository.new }

before do
project_repo.create(name: 'contributors')
action.call(params)
end

after do
project_repo.clear
end

it 'returns all projects' do
projects = action.projects.to_a

expect(projects).to all(be_a(Project))
expect(projects.count).to eq 1
end
end
end
end
end end
8 changes: 8 additions & 0 deletions spec/admin/views/projects/index_spec.rb
Expand Up @@ -3,4 +3,12 @@
let(:template) { Hanami::View::Template.new('apps/admin/templates/projects/index.html.slim') } let(:template) { Hanami::View::Template.new('apps/admin/templates/projects/index.html.slim') }
let(:view) { described_class.new(template, exposures) } let(:view) { described_class.new(template, exposures) }
let(:rendered) { view.render } let(:rendered) { view.render }

describe '#link_to_github' do
let(:project) { Project.new(name: 'contributors') }

it 'returns link to project github' do
expect(view.link_to_github(project).to_s).to eq '<a href="https://github.com/hanami/contributors">contributors</a>'
end
end
end end

0 comments on commit fe8a439

Please sign in to comment.