/
belongs_to.feature
145 lines (129 loc) · 4.19 KB
/
belongs_to.feature
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Feature: Belongs To
A resource belongs to another resource
Background:
Given I am logged in
And a post with the title "Hello World" written by "John Doe" exists
And a post with the title "Hello World" written by "Jane Doe" exists
Scenario: Viewing the child resource index page
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user
end
"""
When I go to the last author's posts
Then the "Users" tab should be selected
And I should not see a menu item for "Posts"
And I should see "Displaying 1 Post"
And I should see a link to "Users" in the breadcrumb
And I should see a link to "Jane Doe" in the breadcrumb
Scenario: Updating a child resource page
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user
permit_params :title, :body, :published_date
form do |f|
f.inputs "Your Post" do
f.input :title
f.input :body
end
f.inputs "Publishing" do
f.input :published_date
end
f.actions
end
end
"""
When I go to the last author's last post page
And I follow "Edit Post"
Then I should see the element "form[action='/admin/users/2/posts/2']"
And I should see a link to "Hello World" in the breadcrumb
When I press "Update Post"
Then I should see "Post was successfully updated."
Scenario: Updating a child resource page with custom configuration
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :author, class_name: "User", param: "user_id", route_name: "user"
permit_params :title
form do |f|
f.actions
end
end
"""
When I go to the last author's last post page
And I follow "Edit Post"
Then I should see the element "form[action='/admin/users/2/posts/2']"
And I should see a link to "Hello World" in the breadcrumb
When I press "Update Post"
Then I should see "Post was successfully updated."
Scenario: Creating a child resource page
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user
permit_params :title, :body, :published_date
form do |f|
f.inputs "Your Post" do
f.input :title
f.input :body
end
f.inputs "Publishing" do
f.input :published_date
end
f.actions
end
end
"""
When I go to the last author's posts
And I follow "New Post"
Then I should see the element "form[action='/admin/users/2/posts']"
When I fill in "Title" with "Hello World"
And I fill in "Body" with "This is the body"
And I press "Create Post"
Then I should see "Post was successfully created."
And I should see the attribute "Title" with "Hello World"
And I should see the attribute "Body" with "This is the body"
And I should see the attribute "Author" with "Jane Doe"
Scenario: Viewing a child resource page
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user
end
"""
When I go to the last author's posts
And I follow "View"
Then I should be on the last author's last post page
And the "Users" tab should be selected
Scenario: When the belongs to is optional
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user, optional: true
end
"""
When I go to the last author's posts
Then the "Users" tab should be selected
And I should see a menu item for "Posts"
When I follow "Posts"
Then the "Posts" tab should be selected
Scenario: Displaying belongs to resources in main menu
Given a configuration of:
"""
ActiveAdmin.register User
ActiveAdmin.register Post do
belongs_to :user
navigation_menu :user
end
"""
When I go to the last author's posts
And I follow "View"
Then the "Posts" tab should be selected