new_page.feature 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Feature: New Page
  2. Customizing the form to create new resources
  3. Background:
  4. Given a category named "Music" exists
  5. Given a user named "John Doe" exists
  6. And I am logged in
  7. Given a configuration of:
  8. """
  9. ActiveAdmin.register Post
  10. """
  11. When I am on the index page for posts
  12. Scenario: Default form with no config
  13. Given I follow "New Post"
  14. When I fill in "Title" with "Hello World"
  15. And I fill in "Body" with "This is the body"
  16. And I select "Music" from "Category"
  17. And I select "John Doe" from "Author"
  18. And I press "Create Post"
  19. Then I should see "Post was successfully created."
  20. And I should see the attribute "Title" with "Hello World"
  21. And I should see the attribute "Body" with "This is the body"
  22. And I should see the attribute "Category" with "Music"
  23. And I should see the attribute "Author" with "John Doe"
  24. Scenario: Generating a custom form
  25. Given a configuration of:
  26. """
  27. ActiveAdmin.register Post do
  28. form do |f|
  29. f.inputs "Your Post" do
  30. f.input :title
  31. f.input :body
  32. end
  33. f.inputs "Publishing" do
  34. f.input :published_at
  35. end
  36. f.buttons
  37. end
  38. end
  39. """
  40. Given I follow "New Post"
  41. Then I should see a fieldset titled "Your Post"
  42. And I should see a fieldset titled "Publishing"
  43. When I fill in "Title" with "Hello World"
  44. And I fill in "Body" with "This is the body"
  45. And I press "Create Post"
  46. Then I should see "Post was successfully created."
  47. And I should see the attribute "Title" with "Hello World"
  48. And I should see the attribute "Body" with "This is the body"
  49. Scenario: Generating a form from a partial
  50. Given "app/views/admin/posts/_form.html.erb" contains:
  51. """
  52. <% url = @post.new_record? ? admin_posts_path : admin_post_path(@post) %>
  53. <%= active_admin_form_for @post, :url => url do |f|
  54. f.inputs :title, :body
  55. f.buttons
  56. end %>
  57. """
  58. Given a configuration of:
  59. """
  60. ActiveAdmin.register Post do
  61. form :partial => "form"
  62. end
  63. """
  64. Given I follow "New Post"
  65. When I fill in "Title" with "Hello World"
  66. And I fill in "Body" with "This is the body"
  67. And I press "Create Post"
  68. Then I should see "Post was successfully created."
  69. And I should see the attribute "Title" with "Hello World"
  70. And I should see the attribute "Body" with "This is the body"
  71. Scenario: Displaying fields at runtime
  72. Given a configuration of:
  73. """
  74. ActiveAdmin.register Post do
  75. form do |f|
  76. f.inputs "Your Post" do
  77. if current_admin_user && false
  78. f.input :title
  79. end
  80. f.input :body
  81. end
  82. f.inputs "Publishing" do
  83. f.input :published_at
  84. end
  85. f.buttons
  86. end
  87. end
  88. """
  89. Given I follow "New Post"
  90. Then I should not see "Title"
  91. And I should see "Body"