<commit_before># encoding: utf-8
require "spec_helper"

module Refinery
  module Admin
    describe "Pages" do
      login_refinery_user

      context "when no pages" do
        before(:each) { Refinery::Page.destroy_all }

        it "invites to create one" do
          visit refinery_admin_pages_path
          page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
        end
      end

      describe "action links" do
        it "shows add new page link" do
          visit refinery_admin_pages_path

          within "#actions" do
            page.should have_content("Add new page")
            page.should have_selector("a[href='/refinery/pages/new']")
          end
        end

        context "when no pages" do
          before(:each) { Refinery::Page.destroy_all }

          it "doesn't show reorder pages link" do
            visit refinery_admin_pages_path

            within "#actions" do
              page.should have_no_content("Reorder pages")
              page.should have_no_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when some pages exist" do
          before(:each) { 2.times { FactoryGirl.create(:page) } }

          it "shows reorder pages link" do
            visit refinery_admin_pages_path

            within "#actions" do
              page.should have_content("Reorder pages")
              page.should have_selector("a[href='/refinery/pages']")
            end
          end
        end
      end

      describe "new/create" do
        it "allows to create page" do
          visit refinery_admin_pages_path

          click_link "Add new page"

          fill_in "Title", :with => "My first page"
          click_button "Save"

          page.should have_content("'My first page' was successfully added.")
          # TODO: figure out why these matchers fail?
          # page.should have_content("Remove this page forever")
          # page.should have_selector("a[href='/refinery/pages/my-first-page']")
          # page.should have_content("Edit this page")
          # page.should have_selector("a[href='/refinery/pages/my-first-page/edit']")
          # page.should have_content("Add a new child page")
          # page.should have_selector("a[href*='/refinery/pages/new?parent_id=']")
          # page.should have_content("View this page live")
          # page.should have_selector("a[href='/pages/my-first-page']")<commit_msg>added spec to test tree expansion<commit_after># encoding: utf-8
require "spec_helper"

module Refinery
  module Admin
    describe "Pages" do
      login_refinery_user

      context "when no pages" do
        before(:each) { Refinery::Page.destroy_all }

        it "invites to create one" do
          visit refinery_admin_pages_path
          page.should have_content(%q{There are no pages yet. Click "Add new page" to add your first page.})
        end
      end

      describe "action links" do
        it "shows add new page link" do
          visit refinery_admin_pages_path

          within "#actions" do
            page.should have_content("Add new page")
            page.should have_selector("a[href='/refinery/pages/new']")
          end
        end

        context "when no pages" do
          before(:each) { Refinery::Page.destroy_all }

          it "doesn't show reorder pages link" do
            visit refinery_admin_pages_path

            within "#actions" do
              page.should have_no_content("Reorder pages")
              page.should have_no_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when some pages exist" do
          before(:each) { 2.times { FactoryGirl.create(:page) } }

          it "shows reorder pages link" do
            visit refinery_admin_pages_path

            within "#actions" do
              page.should have_content("Reorder pages")
              page.should have_selector("a[href='/refinery/pages']")
            end
          end
        end

        context "when sub pages exist" do
          before do
            parent = FactoryGirl.create(:page, :title => "Our Company")
            FactoryGirl.create(:page, :parent => parent, :title => 'Our Team')
            FactoryGirl.create(:page, :parent => parent, :title => 'Our Locations')

            visit refinery_admin_pages_path
          end

          it "should show parent page" do
            page.should have_content("Our Company")
          end

          it "should not show children" do
            page.should_not have_content("Our Team")
            page.should_not have_content("Our Locations")
          end

          it "should expand children", :js => true do
            find(".toggle").click

            page.should have_content("Our Team")
            page.should have_content("Our Locations")
          end
        end
      end

      describe "new/create" do
        it "allows to create page" do
          visit refinery_admin_pages_path

          click_link "Add new page"

          fill_in "Title", :with => "My first page"
          click_button "Save"

          page.should have_content("'My first page' was successfully added.")
          # TODO: figure out why these matchers fail?
          # page.should have_content("Remove this page forever")
          # page.should have_selector("a[href='/refinery/pages/my-first-page']")
          # page.should have_content("Edit this page")
          # page.should have_selector("a[href='/refinery/pages/my-first-page/edit']")
          # page.should have_content("Add a new child page")
          # page.should have_selector("a[href*='/refinery/pages/new?parent_id=']")
          # page.should have_content("View this page live")
          # page.should have_selector("a[href='/pages/my-first-page']")
{'fraction_non_alphanumeric': 0.09752747252747253, 'fraction_numerical': 0.0006868131868131869, 'mean_word_length': 2.0593487394957983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4732869', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1568, 'n_words': 451}