<commit_before>require_relative '../test_helper'

class Me::PagesControllerTest < ActionController::TestCase
  fixtures :users, :pages, :user_participations

  def test_get_index_view
    login_as users(:blue)
    get :index
    assert_response :success
  end

  def test_list_pages
    login_as users(:blue)
    xhr :post, :index
    assert_response :success
  end

  def test_filter_by_own_pages
    pending "filter by me not implemented yet" do
      login_as users(:blue)
      xhr :post, :index, add: "owned-by-me"
      assert_response :success
      assert pages = assigns(:pages)
      assert_nil pages.detect{|page| page.owner != users(:blue)}
    end
  end

  def test_filter_by_created_by_me
    login_as users(:blue)
    xhr :post, :index, add: "created-by-me"
    assert_response :success
    assert pages = assigns(:pages)
    assert_nil pages.detect{|page| page.created_by != users(:blue)}
  end

  def test_list_page_with_long_title
    title = 'VeryLongTitleWithNoSpaceThatWillBeFarTooLongToFitIntoTheTableColumnAndInTurnBreakTheLayoutUnlessItIsBrokenUsingHiddenHyphens'
    expected = 'VeryLongTitleWithNoS&shy;paceThatWillBeFarToo&shy;LongToFitIntoTheTabl&shy;eColumnAndInTurnBrea&shy;kTheLayoutUnlessItIs&shy;BrokenUsingHiddenHyp&shy;hens'
    page = FactoryGirl.build :wiki_page, :title => title, :owner => users(:blue)
    Page.expects(:paginate_by_path).returns([page])
    login_as users(:blue)
    xhr :get, :index
    assert_response :success
    assert assigns(:pages).include?(page)
    assert response.body.include?(expected), "Expected #{response.body} to include #{expected}."
  end
<commit_msg>test empty page list in me pages view<commit_after>require_relative '../test_helper'

class Me::PagesControllerTest < ActionController::TestCase
  fixtures :users, :pages, :user_participations, :page_terms

  def test_get_index_view
    login_as users(:blue)
    get :index
    assert_response :success
  end

  def test_list_pages
    login_as users(:blue)
    xhr :post, :index
    assert !assigns(:pages).empty?, "blue should have some pages to render"
    assert_response :success
  end

  def test_empty_list
    user = FactoryGirl.create :user
    login_as user
    xhr :post, :index
    assert assigns(:pages).empty?
    assert_response :success
  end

  def test_filter_by_own_pages
    pending "filter by me not implemented yet" do
      login_as users(:blue)
      xhr :post, :index, add: "owned-by-me"
      assert_response :success
      assert pages = assigns(:pages)
      assert_nil pages.detect{|page| page.owner != users(:blue)}
    end
  end

  def test_filter_by_created_by_me
    login_as users(:blue)
    xhr :post, :index, add: "created-by-me"
    assert_response :success
    assert pages = assigns(:pages)
    assert !pages.empty?, "blue should have some own pages to render"
    assert_nil pages.detect{|page| page.created_by != users(:blue)}
  end

  def test_list_page_with_long_title
    title = 'VeryLongTitleWithNoSpaceThatWillBeFarTooLongToFitIntoTheTableColumnAndInTurnBreakTheLayoutUnlessItIsBrokenUsingHiddenHyphens'
    expected = 'VeryLongTitleWithNoS&shy;paceThatWillBeFarToo&shy;LongToFitIntoTheTabl&shy;eColumnAndInTurnBrea&shy;kTheLayoutUnlessItIs&shy;BrokenUsingHiddenHyp&shy;hens'
    page = FactoryGirl.build :wiki_page, :title => title, :owner => users(:blue)
    Page.expects(:paginate_by_path).returns([page])
    login_as users(:blue)
    xhr :get, :index
    assert_response :success
    assert assigns(:pages).include?(page)
    assert response.body.include?(expected), "Expected #{response.body} to include #{expected}."
  end

{'fraction_non_alphanumeric': 0.09630863169580905, 'fraction_numerical': 0.0, 'mean_word_length': 4.6049766718507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3007159', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1140, 'n_words': 254}