require "rails_helper"

RSpec.describe Testing::PageGenerator do

  describe "#create_page" do

    it "will create a page given the file_name of the appropriate configuration file" do
      # Copy Page Def from /spec/fixtures into config/testing/page_definitions

      file_path      = Rails.root.join("config", "testing", "page_definitions", "test-page.yml")
      test_file_path = Rails.root.join("spec", "fixtures", "test-page.yml")

      FileUtils.cp(test_file_path, file_path) unless File.exist?(file_path) #clear out any old files from previous test runs
      expect { Testing::PageGenerator.create_page("test-page") }.to change { Page.count }.from(0).to(1)
      page = Page.first
      expect(page.name).to eq "Test Page"
      expect(page.title_text).to eq "Best Text Ever"
      expect(page.description).to eq "Best Description Ever"
    end

  end

end
