Skip to content

Commit

Permalink
Fixes a bug where failing at publishing a note would redirect to Admi…
Browse files Browse the repository at this point in the history
…n::ContentController#edit and crash the application instead of redirecting to Admin::NotesController#edit as it should. Issue publify#247.

Makes Admin::NotesController inherits from Admin::BaseController like Admin::ContentController and Admin::PageController.

Moves private method parse_date_time from Admin::ContentController to Admin::BaseController to avoid code duplication.
  • Loading branch information
Frédéric de Villamil committed Sep 19, 2013
1 parent a4defc2 commit f0b9bc8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 8 additions & 0 deletions app/controllers/admin/base_controller.rb
Expand Up @@ -8,6 +8,14 @@ class Admin::BaseController < ApplicationController

private

def parse_date_time(str)
begin
DateTime.strptime(str, "%B %e, %Y %I:%M %p GMT%z").utc
rescue
Time.parse(str).utc rescue nil
end
end

def update_settings_with!(params)
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
Expand Down
8 changes: 0 additions & 8 deletions app/controllers/admin/content_controller.rb
Expand Up @@ -149,14 +149,6 @@ def set_the_flash

private

def parse_date_time(str)
begin
DateTime.strptime(str, "%B %e, %Y %I:%M %p GMT%z").utc
rescue
Time.parse(str).utc rescue nil
end
end

def load_resources
@post_types = PostType.find(:all)
@images = Resource.images_by_created_at.page(params[:page]).per(10)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/notes_controller.rb
@@ -1,6 +1,6 @@
module Admin; end

class Admin::NotesController < Admin::ContentController
class Admin::NotesController < Admin::BaseController
layout "administration"
cache_sweeper :blog_sweeper

Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/admin/notes_controller_spec.rb
Expand Up @@ -79,6 +79,16 @@
it {expect(response).to redirect_to(controller: 'notes', action: 'new')}
it {expect(Note.count).to eq(2) }
end

context "With missing params" do
before :each do
Note.delete_all
post :new, note: { }
end

it {expect(response).to render_template(controller: 'notes', action: 'edit')}
it {expect(Note.count).to eq(0) }
end
end
end

Expand Down

0 comments on commit f0b9bc8

Please sign in to comment.