<commit_before>require 'spec_helper'

describe Admin::ContentController do
  render_views

  describe 'article merging' do
    context 'merging articles as an administrator' do
      before :each do
        @a1 = Factory(:article, :state => 'draft')
        @a2 = Factory(:article, :state => 'draft')
        Factory(:blog)
        @user = Factory(:user, :profile => Factory(:profile_admin, :label => Profile::ADMIN))
        request.session = { :user => @user.id }
      end

      it 'should call the controller merge method' do
        should_receive(:merge).with({:id1 => "1", :id2 => "2"})
        put :merge, {:id1 => "1", :id2 => "2"}
      end

      it 'should call the model method for merging' do
        @a1.should_receive(:merge_with!).with(@a2.id)
        put :merge, {:id1 => "1", :id2 => "2"}
      end

      it 'should render the new admin_content view' do
        @a1.stub!(:merge_with!).with(@a2.id)
        put :merge, {:id1 => "1", :id2 => "2"}
        response.should render_template('/app/views/admin/content/_form.html.erb')
      end
    end

    context 'merging articles a non-admin user' do
      before :each do
        @a1 = Factory(:article, :state => 'draft')
        @a2 = Factory(:article, :state => 'draft')
        #create non-admin user
        Factory(:blog)
        @user = Factory(:user)
        request.session = { :user => @user.id }
      end

      it 'should not call the model method for merging' do
        should_not_receive(:merge).with({:id1 => "1", :id2 => "2"})
        put :merge, {:id1 => "1", :id2 => "2"}
      end

      it 'should not call the controller merge method' do
        @a1.should_not_receive(:merge_with!).with(@a2.id)
        put :merge, {:id1 => "1", :id2 => "2"}
      end

      it 'should render an error view' do
        @a1.stub!(:merge_with!).with(@a2.id)
        put :merge, {:id1 => "1", :id2 => "2"}
        response.should render_template('some error page')
      end
    end

    describe 'article merge semantics' do
      before :each do
        @a1 = Factory(:article, :state => 'draft', :body => "kitty")
        @a2 = Factory(:article, :state => 'draft', :body => "puppy")
        Factory(:blog)
        @user = Factory(:user, :profile => Factory(:profile_admin, :label => Profile::ADMIN))
        request.session = { :user => @user.id }
      end

      it 'should show the contents of both articles in the merged one' do
        put :merge, {:id1 => "1", :id2 => "2"}
        assigns(@a1.body).should == "kittypuppy" 
      end

      it 'shows the authors of both articles on the resulting merged article' do
        pending
      end
    end
  end

  # Like it's a shared, need call everywhere
  shared_examples_for 'index action' 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
      article = Factory(:article, :body => 'once uppon an originally time')
      get :index, :search => {:searchstring => 'originally'}
      assigns(:articles).should == [article]
      response.should render_template('index')<commit_msg>refactoring tests for new semantics<commit_after>require 'spec_helper'

describe Admin::ContentController do
  render_views

  describe 'article merging' do
    context 'merging articles as an administrator' do
      before :each do
        @a1 = Factory(:article, :state => 'draft')
        @a2 = Factory(:article, :state => 'draft')
        Factory(:blog)
        @user = Factory(:user, :profile => Factory(:profile_admin, :label => Profile::ADMIN))
        request.session = { :user => @user.id }
      end

      it 'should call the controller merge method' do
        should_receive(:merge).with({:id => "1", :other_id => "2"})
        put :merge, {:id => "1", :other_id => "2"}
      end

      it 'should call the model method for merging' do
        @a1.should_receive(:merge_with!).with(@a2.id)
        put :merge, {:id => "1", :other_id => "2"}
      end

      it 'should render the new admin_content view' do
        @a1.stub!(:merge_with!).with(@a2.id)
        put :merge, {:id => "1", :other_id => "2"}
        response.should render_template('/app/views/admin/content/_form.html.erb')
      end
    end

    context 'merging articles a non-admin user' do
      before :each do
        @a1 = Factory(:article, :state => 'draft')
        @a2 = Factory(:article, :state => 'draft')
        #create non-admin user
        Factory(:blog)
        @user = Factory(:user)
        request.session = { :user => @user.id }
      end

      it 'should not call the model method for merging' do
        should_not_receive(:merge).with({:id => "1", :other_id => "2"})
        put :merge, {:id => "1", :other_id => "2"}
      end

      it 'should not call the controller merge method' do
        @a1.should_not_receive(:merge_with!).with(@a2.id)
        put :merge, {:id => "1", :other_id => "2"}
      end

      it 'should render an error view' do
        @a1.stub!(:merge_with!).with(@a2.id)
        put :merge, {:id => "1", :other_id => "2"}
        response.should render_template('some error page')
      end
    end

    describe 'article merge semantics' do
      before :each do
        @a1 = Factory(:article, :state => 'draft', :body => "kitty")
        @a2 = Factory(:article, :state => 'draft', :body => "puppy")
        Factory(:blog)
        @user = Factory(:user, :profile => Factory(:profile_admin, :label => Profile::ADMIN))
        request.session = { :user => @user.id }
      end

      it 'should show the contents of both articles in the merged one' do
        put :merge, {:id => "1", :other_id => "2"}
        assigns(@a1.body).should == "<PASSWORD>" 
      end

      it 'shows the authors of both articles on the resulting merged article' do
        pending
      end
    end
  end

  # Like it's a shared, need call everywhere
  shared_examples_for 'index action' 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
      article = Factory(:article, :body => 'once uppon an originally time')
      get :index, :search => {:searchstring => 'originally'}
      assigns(:articles).should == [article]
      response.should render_template('index')
{'fraction_non_alphanumeric': 0.14517556801416348, 'fraction_numerical': 0.014753614635585718, 'mean_word_length': 2.6001062134891133, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3625300', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2032, 'n_words': 639}