@@ -3,31 +3,31 @@ Feature: Index Scoping
33 Viewing resources and scoping them
44
55 Scenario : Viewing resources with one scope and no default
6- Given 10 posts exist
6+ Given 3 posts exist
77 And an index configuration of:
88 """
99 ActiveAdmin.register Post do
1010 scope :all
1111 end
1212 """
1313 Then I should see the scope "All" not selected
14- And I should see the scope "All" with the count 10
15- And I should see 10 posts in the table
14+ And I should see the scope "All" with the count 3
15+ And I should see 3 posts in the table
1616
1717 Scenario : Viewing resources with one scope as the default
18- Given 10 posts exist
18+ Given 3 posts exist
1919 And an index configuration of:
2020 """
2121 ActiveAdmin.register Post do
2222 scope :all, :default => true
2323 end
2424 """
2525 Then I should see the scope "All" selected
26- And I should see the scope "All" with the count 10
27- And I should see 10 posts in the table
26+ And I should see the scope "All" with the count 3
27+ And I should see 3 posts in the table
2828
2929 Scenario : Viewing resources with one scope and no results
30- Given 10 posts exist
30+ Given 3 posts exist
3131 And an index configuration of:
3232 """
3333 ActiveAdmin.register Post do
@@ -36,15 +36,15 @@ Feature: Index Scoping
3636 end
3737 """
3838
39- When I fill in "Search Title" with "Hello World 17 "
39+ When I fill in "Search Title" with "Non Existing Post "
4040 And I press "Filter"
4141 And I should not see the scope "All"
4242
4343 When I am on the index page for posts
4444 Then I should see the scope "All" selected
4545
4646 Scenario : Viewing resources with a scope but scope_count turned off
47- Given 10 posts exist
47+ Given 3 posts exist
4848 And an index configuration of:
4949 """
5050 ActiveAdmin.register Post do
@@ -54,11 +54,11 @@ Feature: Index Scoping
5454 """
5555 Then I should see the scope "All" selected
5656 And I should see the scope "All" with no count
57- And I should see 10 posts in the table
57+ And I should see 3 posts in the table
5858
5959 @scope
6060 Scenario : Viewing resources with a scope and scope count turned off for a single scope
61- Given 10 posts exist
61+ Given 3 posts exist
6262 And an index configuration of:
6363 """
6464 ActiveAdmin.register Post do
@@ -67,11 +67,11 @@ Feature: Index Scoping
6767 """
6868 Then I should see the scope "All" selected
6969 And I should see the scope "All" with no count
70- And I should see 10 posts in the table
70+ And I should see 3 posts in the table
7171
7272 Scenario : Viewing resources when scoping
73- Given 6 posts exist
74- And 4 published posts exist
73+ Given 2 posts exist
74+ And 3 published posts exist
7575 And an index configuration of:
7676 """
7777 ActiveAdmin.register Post do
@@ -81,15 +81,49 @@ Feature: Index Scoping
8181 end
8282 end
8383 """
84- Then I should see the scope "All" with the count 10
85- And I should see 10 posts in the table
86- Then I should see the scope "Published" with the count 4
84+ Then I should see the scope "All" with the count 5
85+ And I should see 5 posts in the table
86+ And I should see the scope "Published" with the count 3
8787 When I follow "Published"
8888 Then I should see the scope "Published" selected
89- And I should see 4 posts in the table
89+ And I should see 3 posts in the table
90+
91+ Scenario : Viewing resources when scoping and filtering
92+ Given 2 posts written by "Daft Punk" exist
93+ Given 1 published posts written by "Daft Punk" exist
94+
95+ Given 1 posts written by "Alfred" exist
96+ Given 2 published posts written by "Alfred" exist
97+
98+ And an index configuration of:
99+ """
100+ ActiveAdmin.register Post do
101+ scope :all, :default => true
102+ scope :published do |posts|
103+ posts.where("published_at IS NOT NULL")
104+ end
105+ end
106+ """
107+ Then I should see the scope "All" with the count 6
108+ And I should see the scope "Published" with the count 3
109+ And I should see 6 posts in the table
110+
111+ When I follow "Published"
112+ Then I should see the scope "Published" selected
113+ And I should see the scope "All" with the count 6
114+ And I should see the scope "Published" with the count 3
115+ And I should see 3 posts in the table
116+
117+ When I select "daft_punk" from "Author"
118+ And I press "Filter"
119+
120+ Then I should see the scope "Published" selected
121+ And I should see the scope "All" with the count 3
122+ And I should see the scope "Published" with the count 1
123+ And I should see 1 posts in the table
90124
91125 Scenario : Viewing resources with optional scopes
92- Given 10 posts exist
126+ Given 3 posts exist
93127 And an index configuration of:
94128 """
95129 ActiveAdmin.register Post do
@@ -109,10 +143,10 @@ Feature: Index Scoping
109143 And I should not see the scope "All"
110144 And I should not see the scope "Today"
111145 And I should see the scope "Shown"
112- And I should see the scope "Default" with the count 10
146+ And I should see the scope "Default" with the count 3
113147
114148 Scenario : Viewing resources with multiple scopes as blocks
115- Given 10 posts exist
149+ Given 3 posts exist
116150 And an index configuration of:
117151 """
118152 ActiveAdmin.register Post do
@@ -126,17 +160,17 @@ Feature: Index Scoping
126160 """
127161 Then I should see the scope "Today" selected
128162 And I should see the scope "Tomorrow" not selected
129- And I should see the scope "Today" with the count 10
163+ And I should see the scope "Today" with the count 3
130164 And I should see the scope "Tomorrow" with the count 0
131- And I should see 10 posts in the table
165+ And I should see 3 posts in the table
132166 And I should see a link to "Tomorrow"
133167
134168 When I follow "Tomorrow"
135169 Then I should see the scope "Tomorrow" selected
136170 And I should see the scope "Today" not selected
137171 And I should see a link to "Today"
138172
139- Scenario : Viewing resources with scopes when a filter is applied
173+ Scenario : Viewing resources with scopes when scoping to user
140174 Given 2 posts written by "Daft Punk" exist
141175 And a post with the title "Monkey Wrench" written by "Foo Fighters" exists
142176 And a post with the title "Everlong" written by "Foo Fighters" exists
@@ -145,6 +179,7 @@ Feature: Index Scoping
145179 ActiveAdmin.register Post do
146180 scope_to :current_user
147181 scope :all, :default => true
182+
148183 filter :title
149184
150185 controller do
@@ -160,3 +195,49 @@ Feature: Index Scoping
160195 And I press "Filter"
161196 Then I should see the scope "All" not selected
162197 And I should see the scope "All" with the count 1
198+
199+ Scenario : Viewing resources when scoping and filtering and group bys and stuff
200+ Given 2 posts written by "Daft Punk" exist
201+ Given 1 published posts written by "Daft Punk" exist
202+
203+ Given 1 posts written by "Alfred" exist
204+
205+ And an index configuration of:
206+ """
207+ ActiveAdmin.register Post do
208+ scope :all, :default => true
209+ scope :published do |posts|
210+ posts.where("published_at IS NOT NULL")
211+ end
212+
213+ index do
214+ column :author_id
215+ column :count
216+ end
217+
218+ config.sort_order = "author_id_asc"
219+
220+ controller do
221+ def scoped_collection
222+ Post.select("author_id, count(*) as count").group("author_id")
223+ end
224+ end
225+ end
226+ """
227+ Then I should see the scope "All" with the count 2
228+ And I should see the scope "Published" with the count 1
229+ And I should see 2 posts in the table
230+
231+ When I follow "Published"
232+ Then I should see the scope "Published" selected
233+ And I should see the scope "All" with the count 2
234+ And I should see the scope "Published" with the count 1
235+ And I should see 1 posts in the table
236+
237+ When I select "daft_punk" from "Author"
238+ And I press "Filter"
239+
240+ Then I should see the scope "Published" selected
241+ And I should see the scope "All" with the count 1
242+ And I should see the scope "Published" with the count 1
243+ And I should see 1 posts in the table
0 commit comments