<commit_before># ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))

context "Frontend" do
  include Rack::Test::Methods

  setup do
    @path = cloned_testpath("examples/sample-blog.git")
    Shwedagon::App.set :blog, @path
  end

  teardown do
    Dir.chdir("/")
    FileUtils.rm_rf(@path)
  end

  test "Basic listing for the example case" do
    get '/'

    assert_match /Pale Blue Dot/, last_response.body
    assert_match /Hello World/, last_response.body
  end

  test "Create a simple post" do
    post_file = create_post('Create new post test', 'Body content for new post')
    assert_equal last_response.status, 302

    # Check whether it has been committed
    repo = Grit::Repo.new @path
    assert_equal repo.log.first.message, "Created #{post_file}"

    get "/"
    assert_match /Create new post test/, last_response.body

    get "/edit/#{post_file}"

    assert_equal last_response.status, 200
    assert_match /Body content for new post/, last_response.body
  end

  test "Edit a post" do
    post_file = create_post('Editable post', 'Text 1')
    
    # Check whether it has been committed
    repo = Grit::Repo.new @path
    assert_equal repo.log.first.message, "Created #{post_file}"

    
    get "/edit/#{post_file}"
    assert_equal last_response.status, 200    
    assert_match /Text 1/, last_response.body
    assert_no_match /Text 1 and Text 2/, last_response.body

    post "/save-post", :post => 
      { :title   => 'Editable post',
        :content => 'Text 1 and Text 2',
        :name    => post_file}

    assert_equal last_response.status, 302    
    
    # Check repo for edit
    assert_equal repo.log.first.message, "Changed #{post_file}"<commit_msg>Test for creating a post with default yaml<commit_after># ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))

context "Frontend" do
  include Rack::Test::Methods

  setup do
    @path = cloned_testpath("examples/sample-blog.git")
    Shwedagon::App.set :blog, @path
  end

  teardown do
    Dir.chdir("/")
    FileUtils.rm_rf(@path)
  end

  test "Basic listing for the example case" do
    get '/'

    assert_match /Pale Blue Dot/, last_response.body
    assert_match /Hello World/, last_response.body
  end

  test "Create a simple post" do
    post_file = create_post('Create new post test', 'Body content for new post')
    assert_equal last_response.status, 302

    # Check whether it has been committed
    repo = Grit::Repo.new @path
    assert_equal repo.log.first.message, "Created #{post_file}"

    get "/"
    assert_match /Create new post test/, last_response.body

    get "/edit/#{post_file}"

    assert_equal last_response.status, 200
    assert_match /Body content for new post/, last_response.body
  end

  test "Create a post with default yaml" do
    yaml_content = <<YAML
youtube: enter_youtube_url
picasa: enter_picasa_url
YAML

    default_yaml = File.join @path, "_default.yml"
    File.open(default_yaml, 'w+') { |file| file.write(yaml_content) }

    assert_equal File.exists?(default_yaml), true

    post_file = create_post('Create new post test', 'Body content for new post')
    post_object = jekyll_post_object(@path, post_file)
    assert_equal post_object.data['youtube'], 'enter_youtube_url'
    assert_equal post_object.data['picasa'], 'enter_picasa_url'
  end

  test "Edit a post" do
    post_file = create_post('Editable post', 'Text 1')
    
    # Check whether it has been committed
    repo = Grit::Repo.new @path
    assert_equal repo.log.first.message, "Created #{post_file}"

    
    get "/edit/#{post_file}"
    assert_equal last_response.status, 200    
    assert_match /Text 1/, last_response.body
    assert_no_match /Text 1 and Text 2/, last_response.body

    post "/save-post", :post => 
      { :title   => 'Editable post',
        :content => 'Text 1 and Text 2',
        :name    => post_file}

    assert_equal last_response.status, 302    
    
    # Check repo for edit
    assert_equal repo.log.first.message, "Changed #{post_file}"
{'fraction_non_alphanumeric': 0.11048367296832802, 'fraction_numerical': 0.009329732383992144, 'mean_word_length': 3.230529595015576, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4286501', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1277, 'n_words': 370}