/spec/features/pages_spec.rb

https://github.com/metaminded/contentr · Ruby · 73 lines · 66 code · 7 blank · 0 comment · 0 complexity · ec9b5327c7fb4783f1de5cc095fd01bf MD5 · raw file

  1. require 'spec_helper'
  2. feature "pages" do
  3. scenario 'displays the content', js: true do
  4. site = create(:site, slug: 'en', published: true)
  5. a = create(:article, title: 'wicked product', body: 'this article is awesome!').reload
  6. content_page = create(:page, name: 'info', parent: a.default_page,
  7. slug: 'info', published: true, page_type: create(:page_type))
  8. paragraph = create(:paragraph, page: content_page, body: 'hello world!', visible: true)
  9. paragraph.publish!
  10. visit "/en/articles/#{a.id}/info"
  11. expect(content_page.paragraphs.count).to be 1
  12. expect(page).to have_content('hello world!')
  13. end
  14. scenario 'able to create content on a linked page', js: true do
  15. login_as_admin
  16. a = create(:article)
  17. visit article_path(id: a)
  18. expect(page).to have_no_content('Hello World!')
  19. click_link 'body'
  20. select 'Standard', from: 'choose-paragraph-type'
  21. find('#add_paragraph_btn').trigger('click')
  22. expect(page).to have_css('.panel-heading', text: 'Edit Paragraph')
  23. fill_in 'Headline', with: 'Hello World!'
  24. fill_in 'Body', with: 'lorem ipsum'
  25. expect(page).to have_no_css('.paragraph-box .panel-heading')
  26. click_button 'Create Standard paragraph'
  27. expect(page).to have_css('.paragraph-box .panel-heading', text: 'Standard paragraph')
  28. visit article_path(id: a)
  29. expect(page).to have_content('Hello World!')
  30. end
  31. scenario 'able to cancel editing of an existing paragraph', js: true do
  32. login_as_admin
  33. a = create(:article)
  34. visit article_path(id: a)
  35. expect(page).to have_no_content('Hello World!')
  36. click_link 'body'
  37. select 'Standard', from: 'choose-paragraph-type'
  38. find('#add_paragraph_btn').trigger('click')
  39. expect(page).to have_css('.panel-heading', text: 'Edit Paragraph')
  40. fill_in 'Headline', with: 'Hello World!'
  41. fill_in 'Body', with: 'lorem ipsum'
  42. expect(page).to have_no_css('.paragraph-box .panel-heading')
  43. click_button 'Create Standard paragraph'
  44. expect(page).to have_css('.paragraph-box .panel-heading', text: 'Standard paragraph')
  45. find('.paragraph-edit-btn').click
  46. expect(page).to have_css('.paragraph-edit-box .panel-heading', text: 'Edit Paragraph')
  47. click_link 'Cancel'
  48. expect(page).to have_css('.paragraph-box .panel-heading', text: 'Standard paragraph')
  49. end
  50. context 'unpublished page' do
  51. scenario 'an authorized user can see the unpublished page' do
  52. login_as_admin
  53. a = create(:article, title: 'wicked product', body: 'this article is awesome!').reload
  54. content_page = create(:page, name: 'info', parent: a.default_page,
  55. slug: 'info', published: false, page_type: create(:page_type))
  56. visit content_page.url
  57. expect(page.status_code).to be(200)
  58. end
  59. scenario 'a non-authorized user gets a 404' do
  60. a = create(:article, title: 'wicked product', body: 'this article is awesome!').reload
  61. content_page = create(:page, name: 'info', parent: a.default_page,
  62. slug: 'info', published: false, page_type: create(:page_type))
  63. expect{visit content_page.url}.to raise_error(ActionController::RoutingError)
  64. end
  65. end
  66. end