ref: master
test/integration/manage_documents_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
require_relative "../test_helper" class ManageDocumentsTest < ActionDispatch::IntegrationTest all_fixtures def test_creation_of_a_new_article user = create_user('myuser') user.activate login('myuser', 'myuser') assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{user.login}" } get '/myprofile/myuser' assert_response :success assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms' } get '/myprofile/myuser/cms/new' assert_response :success assert_tag :tag => 'a', :attributes => { :href => '/myprofile/myuser/cms/new?type=TextArticle' } get '/myprofile/myuser/cms/new?type=TextArticle' assert_response :success assert_tag :tag => 'form', :attributes => { :action => '/myprofile/myuser/cms/new', :method => /post/i } assert_difference 'Article.count' do post_via_redirect '/myprofile/myuser/cms/new', :type => 'TextArticle', :article => { :name => 'my article', :body => 'this is the body of ther article'} end assert_response :success a = Article.find_by(path: 'my-article') assert_equal "/myuser/#{a.slug}", path end def test_update_of_an_existing_article profile = create_user('myuser').person profile.user.activate article = create_article(profile, :name => 'my-article') article.save! login('myuser', 'myuser') assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}" } 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/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_via_redirect "/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 :success a = Article.find_by path: 'my-article' assert_equal "/myuser/#{a.slug}", path end def test_removing_an_article profile = create_user('myuser').person profile.user.activate article = create_article(profile, :name => 'my-article') article.save! login('myuser', 'myuser') assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}" } 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/destroy/#{article.id}", 'data-confirm' => /Are you sure/ } post_via_redirect "/myprofile/myuser/cms/destroy/#{article.id}" assert_response :success assert_equal "/myuser", path # the article was actually deleted assert_raise ActiveRecord::RecordNotFound do Article.find(article.id) end end protected def create_article(profile, options) a = TextArticle.new(options) a.profile = profile a.save! a end end |