<commit_before>require "#{File.dirname(__FILE__)}/../test_helper"

class ManageDocumentsTest < ActionController::IntegrationTest

  all_fixtures

  def test_creation_of_a_new_article
    create_user('myuser')

    login('myuser', 'myuser')

    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser'  }
    get '/myprofile/myuser'
    
    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' }
    get '/myprofile/myuser/cms/new'

    assert_tag :tag => 'form', :attributes => { :action => '/myprofile/myuser/cms/new', :method => /post/i }

    assert_difference Article, :count do
      post '/myprofile/myuser/cms/new', :article => { :name => 'my article', :body => 'this is the body of ther article'}
    end

    assert_response :redirect
    follow_redirect!
    a = Article.find_by_path('my-article')
    assert_equal "/myprofile/myuser/cms/view/#{a.id}", path
  end

  def test_update_of_an_existing_article
    profile = create_user('myuser').person
    article = profile.articles.build(:name => 'my-article')
    article.save!

    login('myuser', 'myuser')

    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser'  }
    get '/myprofile/myuser'
    assert_response :success
    
    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' }
    get '/myprofile/myuser/cms'
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/view/#{article.id}"}
    get "/myprofile/myuser/cms/view/#{article.id}"
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/edit/#{article.id}"}
    get "/myprofile/myuser/cms/edit/#{article.id}"
    assert_response :success

    assert_tag :tag => 'form', :attributes => { :action => "/myprofile/myuser/cms/edit/#{article.id}", :method => /post/i }

    assert_no_difference Article, :count do
      post "/myprofile/myuser/cms/edit/#{article.id}", :article => { :name => 'my article', :body => 'this is the body of the article'}
    end

    article.reload
    assert_equal 'this is the body of the article', article.body

    assert_response :redirect
    follow_redirect!
    a = Article.find_by_path('my-article')
    assert_equal "/myprofile/myuser/cms/view/#{a.id}", path
  end

  def test_removing_an_article
    flunk 'pending'
  end

end
<commit_msg>ActionItem21: adding article removal test<commit_after>require "#{File.dirname(__FILE__)}/../test_helper"

class ManageDocumentsTest < ActionController::IntegrationTest

  all_fixtures

  def test_creation_of_a_new_article
    create_user('myuser')

    login('myuser', 'myuser')

    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser'  }
    get '/myprofile/myuser'
    
    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' }
    get '/myprofile/myuser/cms/new'

    assert_tag :tag => 'form', :attributes => { :action => '/myprofile/myuser/cms/new', :method => /post/i }

    assert_difference Article, :count do
      post '/myprofile/myuser/cms/new', :article => { :name => 'my article', :body => 'this is the body of ther article'}
    end

    assert_response :redirect
    follow_redirect!
    a = Article.find_by_path('my-article')
    assert_equal "/myprofile/myuser/cms/view/#{a.id}", path
  end

  def test_update_of_an_existing_article
    profile = create_user('myuser').person
    article = profile.articles.build(:name => 'my-article')
    article.save!

    login('myuser', 'myuser')

    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser'  }
    get '/myprofile/myuser'
    assert_response :success
    
    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' }
    get '/myprofile/myuser/cms'
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/view/#{article.id}"}
    get "/myprofile/myuser/cms/view/#{article.id}"
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/edit/#{article.id}"}
    get "/myprofile/myuser/cms/edit/#{article.id}"
    assert_response :success

    assert_tag :tag => 'form', :attributes => { :action => "/myprofile/myuser/cms/edit/#{article.id}", :method => /post/i }

    assert_no_difference Article, :count do
      post "/myprofile/myuser/cms/edit/#{article.id}", :article => { :name => 'my article', :body => 'this is the body of the article'}
    end

    article.reload
    assert_equal 'this is the body of the article', article.body

    assert_response :redirect
    follow_redirect!
    a = Article.find_by_path('my-article')
    assert_equal "/myprofile/myuser/cms/view/#{a.id}", path
  end

  def test_removing_an_article
    profile = create_user('myuser').person
    article = profile.articles.build(:name => 'my-article')
    article.save!

    login('myuser', 'myuser')

    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser'  }
    get '/myprofile/myuser'
    assert_response :success
    
    assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' }
    get '/myprofile/myuser/cms'
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/view/#{article.id}"}
    get "/myprofile/myuser/cms/view/#{article.id}"
    assert_response :success

    assert_tag :tag => 'a', :attributes => { :href => "/myprofile/myuser/cms/destroy/#{article.id}", :onclick => /confirm/ }
    post "/myprofile/myuser/cms/destroy/#{article.id}"

    assert_response :redirect
    follow_redirect!
    assert_equal "/myprofile/myuser/cms", path
  
    # the article was actually deleted
    assert_raise ActiveRecord::RecordNotFound do
      Article.find(article.id)
    end
  end

end

{'fraction_non_alphanumeric': 0.16194262011752505, 'fraction_numerical': 0.0003456619426201175, 'mean_word_length': 3.4687258687258686, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, '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': '7138333', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1875, 'n_words': 396}