Skip to content

Commit 10d3f10

Browse files
committed
Merge branch '10-0-stable' into pull-in-10-0-stable
2 parents b5caac9 + 47ba1e4 commit 10d3f10

File tree

7 files changed

+104
-86
lines changed

7 files changed

+104
-86
lines changed

app/controllers/admin/articles_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def autosave
108108

109109
fetch_fresh_or_existing_draft_for_article
110110

111-
@article.attributes = params[:article].permit!
111+
@article.assign_attributes(update_params)
112112

113113
@article.author = current_user
114114
@article.save_attachments!(params[:attachments])

app/controllers/admin/notes_controller.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create
2323
note = new_note
2424

2525
note.state = "published"
26-
note.attributes = params[:note].permit!
26+
note.assign_attributes(note_params)
2727
note.text_filter ||= default_text_filter
2828
note.published_at ||= Time.zone.now
2929
if note.save
@@ -41,7 +41,7 @@ def create
4141
end
4242

4343
def update
44-
@note.attributes = params[:note].permit!
44+
@note.assign_attributes(note_params)
4545
@note.save
4646
redirect_to admin_notes_url
4747
end
@@ -54,6 +54,15 @@ def destroy
5454

5555
private
5656

57+
def note_params
58+
params.require(:note).permit(:text_filter_name,
59+
:body,
60+
:push_to_twitter,
61+
:in_reply_to_status_id,
62+
:permalink,
63+
:published_at)
64+
end
65+
5766
def load_existing_notes
5867
@notes = Note.page(params[:page]).per(this_blog.limit_article_display)
5968
end

app/controllers/admin/seo_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ def update
3030
private
3131

3232
def settings_params
33-
@settings_params ||= params.require(:setting).permit!
33+
@settings_params ||= params.require(:setting).permit(settings_keys)
34+
end
35+
36+
def settings_keys
37+
@setting.settings_keys + [:custom_permalink]
3438
end
3539

3640
VALID_SECTIONS = %w(general titles permalinks).freeze

app/controllers/admin/settings_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def update
3636
VALID_ACTIONS = %w(index write feedback display).freeze
3737

3838
def settings_params
39-
@settings_params ||= params.require(:setting).permit!
39+
@settings_params ||= params.require(:setting).permit(@setting.settings_keys)
4040
end
4141

4242
def action_param

app/controllers/admin/sidebar_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ def index
88

99
# Just update a single active Sidebar instance at once
1010
def update
11-
@sidebar = Sidebar.where(id: params[:id]).first
11+
@sidebar = Sidebar.find(params[:id])
1212
@old_s_index = @sidebar.staged_position || @sidebar.active_position
13-
@sidebar.update params[:configure][@sidebar.id.to_s].permit!
13+
@sidebar.update params.require(:configure)
14+
.require(@sidebar.id.to_s)
15+
.permit(@sidebar.fields.map(&:key))
1416
respond_to do |format|
1517
format.js
1618
format.html do

app/models/config_manager.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def default_for(key)
2828
fields[key.to_s].default
2929
end
3030

31+
def settings_keys
32+
fields.keys
33+
end
34+
3135
private
3236

3337
def add_setting_reader(item)
@@ -65,6 +69,10 @@ def canonicalize(key, value)
6569
self.class.fields[key.to_s].canonicalize(value)
6670
end
6771

72+
def settings_keys
73+
self.class.settings_keys
74+
end
75+
6876
class Item
6977
VALID_TYPES = [:boolean, :integer, :string, :text].freeze
7078

spec/controllers/admin/notes_controller_spec.rb

Lines changed: 74 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,112 +7,107 @@
77

88
let(:admin) { create(:user, :as_admin, twitter: "@getpublify") }
99
let!(:blog) { create(:blog, limit_article_display: 10) }
10+
let(:note) { create(:note, user_id: admin) }
1011

1112
before do
1213
sign_in admin
1314
end
1415

15-
context "with a blog" do
16-
describe "index" do
17-
let!(:notes) { create_list(:note, 2) }
16+
describe "#index" do
17+
let!(:notes) { create_list(:note, 2) }
1818

19-
it "shows the index template" do
20-
get :index
21-
expect(response).to render_template("index")
22-
end
19+
it "shows the index template" do
20+
get :index
21+
expect(response).to render_template("index")
22+
end
2323

24-
it "lists existing notes" do
25-
get :index
26-
expect(assigns(:notes)).to match_array notes
27-
end
24+
it "lists existing notes" do
25+
get :index
26+
expect(assigns(:notes)).to match_array notes
27+
end
2828

29-
it "assigns a new note for the note form" do
30-
get :index
29+
it "assigns a new note for the note form" do
30+
get :index
3131

32-
aggregate_failures do
33-
expect(assigns(:note)).to be_a(Note)
34-
expect(assigns(:note).author).to eq(admin.login)
35-
expect(assigns(:note).user).to eq(admin)
36-
end
32+
aggregate_failures do
33+
expect(assigns(:note)).to be_a(Note)
34+
expect(assigns(:note).author).to eq(admin.login)
35+
expect(assigns(:note).user).to eq(admin)
3736
end
37+
end
3838

39-
it "lists notes without publication date" do
40-
create(:note, published_at: nil)
39+
it "lists notes without publication date" do
40+
create(:note, published_at: nil)
4141

42-
get :index
43-
expect(response).to be_successful
44-
end
42+
get :index
43+
expect(response).to be_successful
4544
end
45+
end
4646

47-
describe "create" do
48-
context "a simple note" do
49-
before { post :create, params: { note: { body: "Emphasis _mine_" } } }
47+
describe "#create" do
48+
context "a simple note" do
49+
before { post :create, params: { note: { body: "Emphasis _mine_" } } }
5050

51-
it { expect(response).to redirect_to(admin_notes_path) }
52-
it { expect(flash[:notice]).to eq(I18n.t("notice.note_successfully_created")) }
53-
end
51+
it { expect(response).to redirect_to(admin_notes_path) }
52+
it { expect(flash[:notice]).to eq(I18n.t("notice.note_successfully_created")) }
53+
end
54+
55+
it "creates a note" do
56+
expect do
57+
post :create, params: { note: { body: "Emphasis _mine_" } }
58+
end.to change(Note, :count).from(0).to(1)
59+
end
5460

55-
it "creates a note" do
56-
expect do
57-
post :create, params: { note: { body: "Emphasis _mine_" } }
58-
end.to change(Note, :count).from(0).to(1)
61+
context "with twitter access configured" do
62+
before do
63+
blog.twitter_consumer_key = "consumer_key"
64+
blog.twitter_consumer_secret = "consumer_secret"
65+
blog.save
66+
67+
admin.twitter_oauth_token = "oauth_token"
68+
admin.twitter_oauth_token_secret = "oauth_token"
69+
admin.save
5970
end
6071

61-
context "with twitter access configured" do
62-
before do
63-
blog.twitter_consumer_key = "consumer_key"
64-
blog.twitter_consumer_secret = "consumer_secret"
65-
blog.save
66-
67-
admin.twitter_oauth_token = "oauth_token"
68-
admin.twitter_oauth_token_secret = "oauth_token"
69-
admin.save
70-
end
71-
72-
it "sends the note to twitter" do
73-
expect(Note.count).to eq(0)
74-
twitter_cli = double(:twitter_cli)
75-
expect(Twitter::Client).to receive(:new).and_return(twitter_cli)
76-
tweet = Struct.new(:attrs).new({ id_str: "2344" })
77-
expect(twitter_cli).to receive(:update).and_return(tweet)
78-
post :create, params: { note: { body: "Emphasis _mine_, arguments *strong*" },
79-
push_to_twitter: "true" }
80-
expect(Note.first.twitter_id).to eq("2344")
81-
end
72+
it "sends the note to twitter" do
73+
expect(Note.count).to eq(0)
74+
twitter_cli = double(:twitter_cli)
75+
expect(Twitter::Client).to receive(:new).and_return(twitter_cli)
76+
tweet = Struct.new(:attrs).new({ id_str: "2344" })
77+
expect(twitter_cli).to receive(:update).and_return(tweet)
78+
post :create, params: { note: { body: "Emphasis _mine_, arguments *strong*" },
79+
push_to_twitter: "true" }
80+
expect(Note.first.twitter_id).to eq("2344")
8281
end
8382
end
83+
end
8484

85-
context "with an existing note from current user" do
86-
let(:note) { create(:note, user_id: admin) }
87-
88-
describe "edit" do
89-
before { get :edit, params: { id: note.id } }
85+
describe "#edit" do
86+
before { get :edit, params: { id: note.id } }
9087

91-
it { expect(response).to be_successful }
92-
it { expect(response).to render_template("edit") }
93-
it { expect(assigns(:note)).to eq(note) }
94-
it { expect(assigns(:notes)).to eq([note]) }
95-
end
88+
it { expect(response).to be_successful }
89+
it { expect(response).to render_template("edit") }
90+
it { expect(assigns(:note)).to eq(note) }
91+
it { expect(assigns(:notes)).to eq([note]) }
92+
end
9693

97-
describe "update" do
98-
before { post :update, params: { id: note.id, note: { body: "new body" } } }
94+
describe "#update" do
95+
before { post :update, params: { id: note.id, note: { body: "new body" } } }
9996

100-
it { expect(response).to redirect_to(action: :index) }
101-
it { expect(note.reload.body).to eq("new body") }
102-
end
97+
it { expect(response).to redirect_to(action: :index) }
98+
it { expect(note.reload.body).to eq("new body") }
99+
end
103100

104-
describe "show" do
105-
before { get :show, params: { id: note.id } }
101+
describe "#show" do
102+
before { get :show, params: { id: note.id } }
106103

107-
it { expect(response).to render_template("show") }
108-
end
104+
it { expect(response).to render_template("show") }
105+
end
109106

110-
describe "Destroying a note" do
111-
before { post :destroy, params: { id: note.id } }
107+
describe "#destroy" do
108+
before { post :destroy, params: { id: note.id } }
112109

113-
it { expect(response).to redirect_to(admin_notes_path) }
114-
it { expect(Note.count).to eq(0) }
115-
end
116-
end
110+
it { expect(response).to redirect_to(admin_notes_path) }
111+
it { expect(Note.count).to eq(0) }
117112
end
118113
end

0 commit comments

Comments
 (0)