-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-new-project-from-admin' of github.com:Bounga/contri…
…butors into add-new-project-from-admin
- Loading branch information
Showing
32 changed files
with
319 additions
and
25 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,21 @@ | ||
module Admin::Controllers::Settings | ||
class Create | ||
include Admin::Action | ||
|
||
params do | ||
required(:setting).schema do | ||
required(:title).filled(:str?) | ||
end | ||
end | ||
|
||
def call(params) | ||
if params.valid? | ||
SettingRepository.new.create(params[:setting]) | ||
|
||
redirect_to routes.settings_path | ||
else | ||
self.status = 422 | ||
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,11 @@ | ||
module Admin::Controllers::Settings | ||
class Index | ||
include Admin::Action | ||
|
||
expose :setting_history | ||
|
||
def call(params) | ||
@setting_history = SettingRepository.new.history | ||
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,11 @@ | ||
module Admin::Controllers::Settings | ||
class New | ||
include Admin::Action | ||
|
||
expose :settings | ||
|
||
def call(params) | ||
@settings = SettingRepository.new.latest | ||
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,12 @@ | ||
h2 Setting History | ||
|
||
table.table.table-hover | ||
tr | ||
th Title | ||
th Changed at | ||
- setting_history.each do |setting| | ||
tr | ||
td = setting.title | ||
td = setting.created_at | ||
|
||
.new-settings = link_to 'New Settings', routes.new_setting_path |
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,3 @@ | ||
h2 New Settings | ||
|
||
= form(settings) |
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,8 @@ | ||
.admin-pages | ||
ul.nav.nav-pills | ||
li role="presentation" | ||
a href='/admin' Repositories | ||
li role="presentation" | ||
a href='/admin/settings' Settings | ||
li role="presentation" | ||
a href='/' target='_blank' Main app |
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,5 @@ | ||
module Admin::Views::Settings | ||
class Index | ||
include Admin::View | ||
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,14 @@ | ||
module Admin::Views::Settings | ||
class New | ||
include Admin::View | ||
|
||
def form(settings) | ||
form_for :setting, routes.settings_path, class: 'setting-form' do | ||
label :title | ||
text_field :title, value: settings.title | ||
|
||
submit 'Create' | ||
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
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
require 'dry/system/container' | ||
|
||
# Configure the code that will yield each time Admin::Action is included | ||
# This is useful for sharing common functionality | ||
# | ||
# See: http://www.rubydoc.info/gems/hanami-controller#Configuration | ||
ADMIN_USERNAME = ENV.fetch('ADMIN_USERNAME') | ||
ADMIN_PASSWORD = ENV.fetch('ADMIN_PASSWORD') | ||
|
||
class Application < Dry::System::Container | ||
configure | ||
end | ||
# Enable pagination helpers for repositories | ||
CommitRepository.enable_pagination! |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hanami::Model.migration do | ||
change do | ||
create_table :settings do | ||
primary_key :id | ||
|
||
column :title, String | ||
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,5 @@ | ||
Hanami::Model.migration do | ||
change do | ||
add_column :settings, :created_at, DateTime, null: false | ||
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 |
---|---|---|
@@ -1 +0,0 @@ | ||
Hanami::Utils.require!("#{__dir__}/contributors") | ||
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,2 @@ | ||
class Setting < Hanami::Entity | ||
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,12 @@ | ||
require 'hanami/interactor' | ||
|
||
module Operations | ||
class List | ||
include Hanami::Interactor | ||
expose :contributors | ||
|
||
def call | ||
@contributors = [] | ||
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,15 @@ | ||
class SettingRepository < Hanami::Repository | ||
def history | ||
settings | ||
.order{ created_at.desc } | ||
.map_to(Setting) | ||
.to_a | ||
end | ||
|
||
def latest | ||
settings | ||
.order{ created_at.desc } | ||
.limit(1).map_to(Setting) | ||
.one || Setting.new | ||
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,30 @@ | ||
RSpec.describe Admin::Controllers::Settings::Create, type: :action do | ||
let(:action) { described_class.new } | ||
let(:settings_repo) { SettingRepository.new } | ||
|
||
after { settings_repo.clear } | ||
|
||
|
||
describe '#call' do | ||
context 'correct params' do | ||
let(:params) { Hash[setting: {title: 'hello'}] } | ||
|
||
it 'creates a new setting record' do | ||
expect{action.call(params)}.to change{settings_repo.all.count}.by(1) | ||
end | ||
end | ||
|
||
context 'incorrect params' do | ||
let(:params) { Hash[] } | ||
|
||
it 'does not creates a new setting record' do | ||
expect{action.call(params)}.to_not change{settings_repo.all.count} | ||
end | ||
|
||
it 'returns 422' do | ||
response = action.call(params) | ||
expect(response[0]).to eq 422 | ||
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,30 @@ | ||
RSpec.describe Admin::Controllers::Settings::Index, type: :action do | ||
let(:action) { described_class.new } | ||
let(:params) { Hash[] } | ||
let(:settings_repo) { SettingRepository.new } | ||
|
||
after { settings_repo.clear } | ||
|
||
it { expect(action.call(params)).to be_success } | ||
|
||
describe 'expose' do | ||
describe '#setting_history' do | ||
context 'when db empty' do | ||
before { action.call(params) } | ||
|
||
it { expect(action.setting_history).to eq [] } | ||
end | ||
|
||
context 'when db has settings' do | ||
before do | ||
settings_repo.create(title: 'Hanami') | ||
action.call(params) | ||
end | ||
|
||
it { expect(action.setting_history).to be_a Array } | ||
it { expect(action.setting_history).to all(be_a Setting) } | ||
it { expect(action.setting_history.first.title).to eq 'Hanami' } | ||
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,34 @@ | ||
require 'features_helper' | ||
|
||
describe 'Create a setting' do | ||
let(:repo) { SettingRepository.new } | ||
include_context 'authenticated' | ||
|
||
after { repo.clear } | ||
|
||
context 'No setting before' do | ||
it 'can create a new setting' do | ||
visit '/admin/settings/new' | ||
|
||
within 'form#setting-form' do | ||
fill_in 'Title', with: 'Hanami' | ||
|
||
click_button 'Create' | ||
end | ||
|
||
expect(current_path).to eq('/admin/settings') | ||
expect(page).to have_content('Hanami') | ||
end | ||
end | ||
|
||
context 'Previous setting before' do | ||
|
||
before { repo.create(title: 'dry-rb') } | ||
|
||
it 'preview setting value are displayed' do | ||
visit '/admin/settings/new' | ||
|
||
expect(page).to have_field('Title', with: 'dry-rb') | ||
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,3 @@ | ||
RSpec.describe Setting do | ||
# place your tests here | ||
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,7 @@ | ||
RSpec.describe Operations::List do | ||
let(:operation) { described_class.new } | ||
subject { operation.call } | ||
|
||
it { expect(subject).to be_successful } | ||
it { expect(subject.contributors).to eq [] } | ||
end |
Oops, something went wrong.