homesteading_publisher 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c4c085c5383d90bb9159f1fcf480ff6d931543a
4
- data.tar.gz: 58aac952b3fe133362e5cb88be518722600102e0
3
+ metadata.gz: a01e2bed5edf21393b953db3ff52cc1f95225824
4
+ data.tar.gz: 5d948bd4b1f767872ee92b28d91d8e9dac709d98
5
5
  SHA512:
6
- metadata.gz: 8315f49f00fa01e39ac9f7f58df6e806746fccee190bb8a0f162703c853755074735cb256b3c3d7f6e44ce6d3318582f6658fe9aae1e6189b3f3524c62968f13
7
- data.tar.gz: bc7a2de5c62c1b67ab9c53d2499b76c3057450f4bf9abdfdb0083ea582c0ca188c1ec3015b2cb43af24671fb4e5c52748cd0cd319719695f0e99a2a59850be7e
6
+ metadata.gz: 739482b9689a98c5126500070c68e925e21416e6b83299feda53abb3ae4625a6f31f628833c02bfd2c509af4f17b3aeb8ff3eeafae601c7b4d74d78eabc14684
7
+ data.tar.gz: f39a7104f2c0c87d22a4cf4cd564698e71455e898deecbd88b1c8f17731f82fcaaff2a30cbde75829f8aa6d3c2cebaa28d7f65e8d963ada8e2413f4c498a2e11
@@ -0,0 +1,50 @@
1
+ module HomesteadingPublisher
2
+ class SettingsController < ApplicationController
3
+ before_action :set_setting, only: [:show, :edit, :update]
4
+ before_action :all_settings
5
+
6
+ def index
7
+ @page_title = "Settings"
8
+ end
9
+
10
+ def show
11
+ redirect_to settings_path
12
+ end
13
+
14
+ def edit
15
+ @setting = Setting.find(params[:id])
16
+ @page_title = "Editing Setting : #{@setting.name}"
17
+ end
18
+
19
+ def update
20
+ @setting = Setting.find(params[:id])
21
+
22
+ content = (
23
+ @setting.name.downcase == "license" ?
24
+ License.find(setting_params[:content]).short_code :
25
+ @setting.content
26
+ )
27
+ notice = "<h4>Setting: was successfully updated.</h4>
28
+ <p><b>#{@setting.name}</b> : #{content}</p>".html_safe
29
+
30
+ if @setting.update(setting_params)
31
+ redirect_to settings_path, notice: notice
32
+ else
33
+ render action: "edit"
34
+ end
35
+ end
36
+
37
+ private
38
+ def set_setting
39
+ @setting = Setting.find(params[:id])
40
+ end
41
+
42
+ def setting_params
43
+ params.require(:setting).permit(:name, :key, :content)
44
+ end
45
+
46
+ def all_settings
47
+ @settings = Setting.editable.all
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ <% unless flash[:notice].blank? %>
2
+ <div class="alert alert-success"><%= flash[:notice] %></div>
3
+ <% end %>
4
+
5
+ <dl>
6
+ <% @settings.each do |setting| %>
7
+ <dt><%= link_to setting.name, edit_setting_path(setting) %></dt>
8
+
9
+ <dd>
10
+ <% if setting.key == "license" %>
11
+ <%= License.find(setting.content).short_code.html_safe %>
12
+ <% else %>
13
+ <%= setting.content %>
14
+ <% end %>
15
+ </dd>
16
+ <% end %>
17
+ </dl>
@@ -0,0 +1,35 @@
1
+ <article class="h-entry" id="settings">
2
+ <h1 class="p-name"><%= link_to "Settings", settings_path %></h1>
3
+
4
+ <%= form_for(@setting) do |f| %>
5
+ <% if @setting.errors.any? %>
6
+ <div class="alert alert-danger">
7
+ <h4><%= pluralize(@setting.errors.count, "error") %> prohibited this setting from being saved:</h4>
8
+
9
+ <ul>
10
+ <% @setting.errors.full_messages.each do |msg| %>
11
+ <li><%= msg %></li>
12
+ <% end %>
13
+ </ul>
14
+ </div>
15
+ <% end %>
16
+
17
+ <dl>
18
+ <dt>Editing <%= f.label :content, @setting.name %></dt>
19
+ <dd>
20
+ <% if @setting.key == "license" %>
21
+ <%= f.select :content, License.options_for_select %>
22
+ <% else %>
23
+ <%= f.text_field :content, autofocus: true %>
24
+ <% end %>
25
+ </dd>
26
+
27
+ <dd class="actions">
28
+ <%= link_to "Cancel", settings_url, class: "action" %>
29
+ <%= f.button "Save", class: "action-save" %>
30
+ </dd>
31
+ </dl>
32
+ <% end %>
33
+
34
+ <%= render "settings" %>
35
+ </article>
@@ -0,0 +1,5 @@
1
+ <article class="h-entry" id="settings">
2
+ <h1 class="p-name"><%= link_to_unless_current "Settings", settings_path %></h1>
3
+
4
+ <%= render "settings" %>
5
+ </article>
data/config/routes.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  HomesteadingPublisher::Engine.routes.draw do
2
+
3
+ resources :settings, only: [:index, :edit, :show, :update]
4
+
2
5
  get "/posts/new",
3
6
  to: "posts#new",
4
7
  as: "new_post"
@@ -1,3 +1,3 @@
1
1
  module HomesteadingPublisher
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+
3
+ describe HomesteadingPublisher::SettingsController, type: :controller do
4
+ routes { HomesteadingPublisher::Engine.routes }
5
+
6
+ describe "GET index" do
7
+ let!(:non_editable_setting) { create(:setting, editable: false) }
8
+ let!(:editable_setting) { create(:setting, editable: true) }
9
+ before { get :index }
10
+
11
+ it "assings @settings to editable settings" do
12
+ expect(assigns(:settings).to_a).to eq [editable_setting]
13
+ end
14
+
15
+ it "assigns @page_title" do
16
+ expect(assigns(:page_title)).to eq "Settings"
17
+ end
18
+
19
+ it "renders the index template" do
20
+ expect(response).to render_template "index"
21
+ end
22
+ end
23
+
24
+ describe "GET show" do
25
+ let!(:setting) { create(:setting, editable: true) }
26
+ before { get :show, id: setting.id }
27
+
28
+ it "assings @settings to editable settings" do
29
+ expect(assigns(:settings).to_a).to eq [setting]
30
+ end
31
+
32
+ it "assigns @setting" do
33
+ expect(assigns(:setting)).to eq setting
34
+ end
35
+
36
+ it "redirects to settings" do
37
+ expect(response).to redirect_to settings_path
38
+ end
39
+ end
40
+
41
+ describe "GET edit" do
42
+ let!(:setting) { create(:setting, editable: true) }
43
+ before { get :edit, id: setting.id }
44
+
45
+ it "assings @settings to editable settings" do
46
+ expect(assigns(:settings).to_a).to eq [setting]
47
+ end
48
+
49
+ it "assigns @setting" do
50
+ expect(assigns(:setting)).to eq setting
51
+ end
52
+
53
+ it "assigns @page_title" do
54
+ expect(assigns(:page_title)).to eq "Editing Setting : #{setting.name}"
55
+ end
56
+
57
+ it "renders the edit template" do
58
+ expect(response).to render_template "edit"
59
+ end
60
+ end
61
+
62
+ describe "PATCH update" do
63
+ let!(:setting) { create(:setting, editable: true) }
64
+
65
+ it "assings @settings to editable settings" do
66
+ patch :update, id: setting.id, setting: { name: "updated_setting_name"}
67
+ expect(assigns(:settings).to_a).to eq [setting]
68
+ end
69
+
70
+ it "assigns @setting" do
71
+ patch :update, id: setting.id, setting: { name: "updated_setting_name"}
72
+ expect(assigns(:setting)).to eq setting
73
+ end
74
+
75
+ context "when update is successful" do
76
+ before { Setting.any_instance.stub(:update) { true } }
77
+ before { patch :update, id: setting.id, setting: { name: "updated_setting_name"} }
78
+
79
+ it "redirects to settings" do
80
+ expect(response).to redirect_to settings_path
81
+ end
82
+ end
83
+
84
+ context "when update is unsuccessful" do
85
+ before { Setting.any_instance.stub(:update) { false } }
86
+ before { patch :update, id: setting.id, setting: { name: "updated_setting_name"} }
87
+
88
+ it "renders edit template" do
89
+ expect(response).to render_template "edit"
90
+ end
91
+ end
92
+ end
93
+ end