Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2ba9e8
commit f11d7e1
Showing
10 changed files
with
86 additions
and
4 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 New | ||
include Admin::Action | ||
|
||
expose :settings | ||
|
||
def call(params) | ||
@settings = SettingRepository.new.for_display | ||
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 |
---|---|---|
|
@@ -8,3 +8,5 @@ table.table.table-hover | |
tr | ||
td = key | ||
td = value | ||
|
||
.new-settings = link_to 'New Settings', routes.new_settings_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,14 @@ | ||
module Admin::Views::Settings | ||
class New | ||
include Admin::View | ||
|
||
def form(settings) | ||
form_for :setting, routes.create_settings_path 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class SettingRepository < Hanami::Repository | ||
|
||
def for_display | ||
settings.select(:title).first | ||
settings.select(:title).last | ||
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::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
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