Permalink
Browse files

Fix Admin::PagesController specs

  • Loading branch information...
1 parent d4f4ffb commit d2f173f4d92dbf40665023130681375d8995763e @mvz mvz committed Feb 24, 2013
Showing with 15 additions and 9 deletions.
  1. +10 −4 app/controllers/admin/pages_controller.rb
  2. +5 −5 spec/controllers/admin/pages_controller_spec.rb
@@ -17,7 +17,8 @@ def index
def new
@page = Page.new(params[:page])
@page.user_id = current_user.id
- @page.text_filter = set_textfilter
+ @page.text_filter ||= default_textfilter
+
if request.post?
@page.published_at = Time.now
if @page.save
@@ -30,6 +31,7 @@ def new
def edit
@page = Page.find(params[:id])
@page.attributes = params[:page]
+ @page.text_filter ||= default_textfilter
if request.post? and @page.save
flash[:notice] = _('Page was successfully updated.')
redirect_to :action => 'index'
@@ -45,11 +47,15 @@ def destroy
private
- def set_textfilter
- return TextFilter.find_by_name("none") if current_user.visual_editor?
- return current_user.text_filter if @page.id.nil?
+ def default_textfilter
+ if current_user.visual_editor?
+ "none"
+ else
+ current_user.text_filter || blog.text_filter
+ end
end
+
def set_macro
@macros = TextFilter.macro_filters
end
@@ -5,8 +5,10 @@
render_views
before do
- @blog = FactoryGirl.create(:blog)
- @henri = FactoryGirl.create(:user, login: 'henri', profile: FactoryGirl.create(:profile_admin, label: Profile::ADMIN))
+ @blog = create(:blog)
+ @henri = create(:user,
+ login: 'henri',
+ profile: create(:profile_admin))
request.session = { user: @henri.id }
end
@@ -43,11 +45,9 @@
it "should have a text filter" do
get :new
- expect(TextFilter.find_by_name(@blog.text_filter)).to_not be_nil
- assert_equal TextFilter.find_by_name(@blog.text_filter), assigns(:page).text_filter
+ assigns(:page).text_filter.name.should eq 'textile'
end
end
-
end
it "test_create" do

0 comments on commit d2f173f

Please sign in to comment.