<commit_before>require File.dirname(__FILE__) + '/../../../test/test_helper'
require File.dirname(__FILE__) + '/../../spec_helper'
require 'admin/content_controller'

require 'http_mock'

# Re-raise errors caught by the controller.
module Admin
end

class Admin::ContentController; def rescue_action(e) raise e end; end

describe Admin::ContentController do
  integrate_views


  # Like it's a shared, need call everywhere
  describe 'index action', :shared => true do

    it 'should render template index' do
      get 'index'
      response.should render_template('index')
    end

    it 'should see all published in index' do
      get :index, :search => {:published => '0', :published_at => '2008-08', :user_id => '2'}
      response.should render_template('index')
      response.should be_success
    end

    it 'should restrict only by searchstring' do
      get :index, :search => {:searchstring => 'originally'}
      assigns(:articles).should == [contents(:xmltest)]
      response.should render_template('index')
      response.should be_success
    end

    it 'should restrict by searchstring and published_at' do
      get :index, :search => {:searchstring => 'originally', :published_at => '2008-08'}
      assigns(:articles).should be_empty
      response.should render_template('index')
      response.should be_success
    end

  end

  describe 'insert_editor action' do
    
    before do
      @user = users(:tobi)
      request.session = { :user => @user.id }
    end
    
    it 'should render _simple_editor' do
      get(:insert_editor, :editor => 'simple')
      response.should render_template('simple_editor')
    end

    it 'should render _visual_editor' do
      get(:insert_editor, :editor => 'visual')
      response.should render_template('visual_editor')
    end

  end


  describe 'new action', :shared => true do

    it 'should render new with get' do
      get :new
      response.should render_template('new')
      assert_template_has 'article'
    end

    def base_article(options={})
      { :title => "posted via tests!",
        :body => "A good body",
        :keywords => "tagged",
        :allow_comments => '1', 
        :allow_pings => '1' }.merge(options)
    end

    it 'should create article with no comments' do
      post(:new, 'article' => base_article({:allow_comments => '0'}),
                 'categories' => [categories(:software).id])
      assigns(:article).should_not be_allow_comments<commit_msg>partials must be spelled with the preceding underscore.<commit_after>require File.dirname(__FILE__) + '/../../../test/test_helper'
require File.dirname(__FILE__) + '/../../spec_helper'
require 'admin/content_controller'

require 'http_mock'

# Re-raise errors caught by the controller.
module Admin
end

class Admin::ContentController; def rescue_action(e) raise e end; end

describe Admin::ContentController do
  integrate_views


  # Like it's a shared, need call everywhere
  describe 'index action', :shared => true do

    it 'should render template index' do
      get 'index'
      response.should render_template('index')
    end

    it 'should see all published in index' do
      get :index, :search => {:published => '0', :published_at => '2008-08', :user_id => '2'}
      response.should render_template('index')
      response.should be_success
    end

    it 'should restrict only by searchstring' do
      get :index, :search => {:searchstring => 'originally'}
      assigns(:articles).should == [contents(:xmltest)]
      response.should render_template('index')
      response.should be_success
    end

    it 'should restrict by searchstring and published_at' do
      get :index, :search => {:searchstring => 'originally', :published_at => '2008-08'}
      assigns(:articles).should be_empty
      response.should render_template('index')
      response.should be_success
    end

  end

  describe 'insert_editor action' do
    
    before do
      @user = users(:tobi)
      request.session = { :user => @user.id }
    end
    
    it 'should render _simple_editor' do
      get(:insert_editor, :editor => 'simple')
      response.should render_template('_simple_editor')
    end

    it 'should render _visual_editor' do
      get(:insert_editor, :editor => 'visual')
      response.should render_template('_visual_editor')
    end

  end


  describe 'new action', :shared => true do

    it 'should render new with get' do
      get :new
      response.should render_template('new')
      assert_template_has 'article'
    end

    def base_article(options={})
      { :title => "posted via tests!",
        :body => "A good body",
        :keywords => "tagged",
        :allow_comments => '1', 
        :allow_pings => '1' }.merge(options)
    end

    it 'should create article with no comments' do
      post(:new, 'article' => base_article({:allow_comments => '0'}),
                 'categories' => [categories(:software).id])
      assigns(:article).should_not be_allow_comments
{'fraction_non_alphanumeric': 0.12073121735636802, 'fraction_numerical': 0.006830052229811169, 'mean_word_length': 3.118279569892473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2645009', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1393, 'n_words': 422}