Permalink
Browse files

Add admin page to list all available projects in DB

See #39
  • Loading branch information...
Bounga committed Feb 8, 2018
1 parent b2cc14e commit fe8a439225522157e348cd361c7651c19fae7140
@@ -2,7 +2,10 @@ module Admin::Controllers::Projects
class Index
include Admin::Action
expose :projects
def call(params)
@projects = ProjectRepository.new.sorted
end
end
end
@@ -4,5 +4,7 @@ html
title
| Admin
= favicon
= stylesheet 'bootstrap', 'main'
body
= yield
.container
= yield
@@ -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')
@@ -1,5 +1,9 @@
module Admin::Views::Projects
class Index
include Admin::View
def link_to_github(project)
link_to project.name, "https://github.com/hanami/#{project.name}"
end
end
end
@@ -1,2 +1,5 @@
class ProjectRepository < Hanami::Repository
def sorted
projects.order { name.asc }
end
end
@@ -6,4 +6,34 @@
response = action.call(params)
expect(response[0]).to eq 200
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
@@ -3,4 +3,12 @@
let(:template) { Hanami::View::Template.new('apps/admin/templates/projects/index.html.slim') }
let(:view) { described_class.new(template, exposures) }
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

0 comments on commit fe8a439

Please sign in to comment.