|
5 | 5 | describe 'browse the test app' do
|
6 | 6 | let(:password) { 'foobar•secret' }
|
7 | 7 | let(:email) { '[email protected]' }
|
| 8 | + let(:admin_user) do |
| 9 | + AdminUser.where(email: email).first || AdminUser.create!(email: email, password: password) |
| 10 | + end |
| 11 | + let(:other_email) { '[email protected]' } |
| 12 | + let(:other_user) do |
| 13 | + AdminUser.where(email: other_email).first || AdminUser.create!(email: other_email, password: password) |
| 14 | + end |
8 | 15 |
|
9 | 16 | before do
|
10 | 17 | Mongoid.purge!
|
11 |
| - AdminUser.create! email: email, password: password |
| 18 | + expect(admin_user).to be_persisted |
| 19 | + expect(other_user).to be_persisted |
12 | 20 | end
|
13 |
| - before { visit '/admin' } |
14 |
| - |
15 |
| - it 'does something' do |
16 |
| - I18n.t('active_admin.devise.login.submit').should eq('Login') |
17 | 21 |
|
18 |
| - # Auth |
19 |
| - fill_in 'Email', with: email |
20 |
| - fill_in 'Password', with: password |
21 |
| - click_on 'Login' |
| 22 | + context 'when authorized' do |
| 23 | + before do |
| 24 | + visit '/admin' |
22 | 25 |
|
23 |
| - # New |
24 |
| - click_on 'Posts' |
25 |
| - click_on 'New Post' |
26 |
| - fill_in 'Title', with: 'dhh screencast' |
27 |
| - fill_in 'Body', with: 'is still the best intro to rails' |
| 26 | + I18n.t('active_admin.devise.login.submit').should eq('Login') |
28 | 27 |
|
29 |
| - # Create |
30 |
| - click_on 'Create Post' |
| 28 | + # Auth |
| 29 | + fill_in 'Email', with: email |
| 30 | + fill_in 'Password', with: password |
| 31 | + click_on 'Login' |
| 32 | + end |
31 | 33 |
|
32 |
| - within '.attributes_table.post' do |
33 |
| - page.should have_content('dhh screencast') |
34 |
| - page.should have_content('is still the best intro to rails') |
| 34 | + it 'creates and edits a new post' do |
| 35 | + # New |
| 36 | + click_on 'Posts' |
| 37 | + click_on 'New Post' |
| 38 | + fill_in 'Title', with: 'dhh screencast' |
| 39 | + fill_in 'Body', with: 'is still the best intro to rails' |
| 40 | + |
| 41 | + # Create |
| 42 | + click_on 'Create Post' |
| 43 | + |
| 44 | + within '.attributes_table.post' do |
| 45 | + page.should have_content('dhh screencast') |
| 46 | + page.should have_content('is still the best intro to rails') |
| 47 | + end |
| 48 | + |
| 49 | + # Edit |
| 50 | + click_on 'Edit Post' |
| 51 | + fill_in 'Title', with: 'DHH original screencast' |
| 52 | + |
| 53 | + # Update |
| 54 | + click_on 'Update Post' |
| 55 | + |
| 56 | + within '.attributes_table.post' do |
| 57 | + page.should have_content('DHH original screencast') |
| 58 | + page.should have_content('is still the best intro to rails') |
| 59 | + end |
| 60 | + |
| 61 | + # List |
| 62 | + within('.breadcrumb') { click_on 'Posts' } |
| 63 | + within '#index_table_posts' do |
| 64 | + page.should have_content('DHH original screencast') |
| 65 | + page.should have_content('is still the best intro to rails') |
| 66 | + end |
35 | 67 | end
|
36 | 68 |
|
37 |
| - # Edit |
38 |
| - click_on 'Edit Post' |
39 |
| - fill_in 'Title', with: 'DHH original screencast' |
| 69 | + context 'with 1 post' do |
40 | 70 |
|
41 |
| - # Update |
42 |
| - click_on 'Update Post' |
| 71 | + before do |
| 72 | + Post.create!(title: 'Quick Brown Fox', body: 'The quick brown fox jumps over the lazy dog.', view_count: 5, admin_user: admin_user, other_user: other_user) |
| 73 | + |
| 74 | + click_on 'Posts' |
| 75 | + end |
| 76 | + |
| 77 | + describe 'filters' do |
| 78 | + describe 'string' do |
| 79 | + it 'searches by title' do |
| 80 | + fill_in 'Search Title', with: 'Brown' |
| 81 | + click_on 'Filter' |
43 | 82 |
|
44 |
| - within '.attributes_table.post' do |
45 |
| - page.should have_content('DHH original screencast') |
46 |
| - page.should have_content('is still the best intro to rails') |
47 |
| - end |
| 83 | + within '#index_table_posts' do |
| 84 | + page.should have_content('Quick Brown Fox') |
| 85 | + end |
48 | 86 |
|
49 |
| - # List |
50 |
| - within('.breadcrumb') { click_on 'Posts' } |
51 |
| - within '#index_table_posts' do |
52 |
| - page.should have_content('DHH original screencast') |
53 |
| - page.should have_content('is still the best intro to rails') |
54 |
| - end |
| 87 | + fill_in 'Search Title', with: 'dog' |
| 88 | + click_on 'Filter' |
| 89 | + page.should_not have_content('Quick Brown Fox') |
| 90 | + |
| 91 | + fill_in 'Search Title', with: '' |
| 92 | + click_on 'Filter' |
| 93 | + |
| 94 | + page.should have_content('Displaying 1 Post') |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + describe 'date_range' do |
| 99 | + it 'searches by created_at range' do |
| 100 | + fill_in 'q[created_at_gte]', with: 1.day.ago.to_datetime.strftime("%Y-%m-%d") |
| 101 | + fill_in 'q[created_at_lte]', with: 2.days.from_now.to_datetime.strftime("%Y-%m-%d") |
| 102 | + click_on 'Filter' |
| 103 | + |
| 104 | + within '#index_table_posts' do |
| 105 | + page.should have_content('Quick Brown Fox') |
| 106 | + end |
55 | 107 |
|
56 |
| - # Filter |
57 |
| - fill_in 'Search Title', with: 'original' |
58 |
| - click_on 'Filter' |
| 108 | + fill_in 'q[created_at_gte]', with: 1.day.from_now.to_datetime.strftime("%Y-%m-%d") |
| 109 | + click_on 'Filter' |
| 110 | + page.should_not have_content('Quick Brown Fox') |
59 | 111 |
|
60 |
| - within '#index_table_posts' do |
61 |
| - page.should have_content('DHH original screencast') |
62 |
| - end |
| 112 | + fill_in 'q[created_at_gte]', with: '' |
| 113 | + fill_in 'q[created_at_lte]', with: '' |
| 114 | + click_on 'Filter' |
| 115 | + |
| 116 | + page.should have_content('Displaying 1 Post') |
| 117 | + end |
| 118 | + end |
| 119 | + |
| 120 | + describe 'numeric' do |
| 121 | + it 'searches by created_at range', js: true do |
| 122 | + within '.filter_numeric' do |
| 123 | + find(:select).find('option[value=view_count_eq]').select_option |
| 124 | + end |
| 125 | + fill_in 'View count', with: '5' |
| 126 | + click_on 'Filter' |
| 127 | + |
| 128 | + within '#index_table_posts' do |
| 129 | + page.should have_content('Quick Brown Fox') |
| 130 | + end |
63 | 131 |
|
64 |
| - fill_in 'Search Title', with: 'orizinal' |
65 |
| - click_on 'Filter' |
66 |
| - page.should_not have_content('DHH original screencast') |
| 132 | + fill_in 'View count', with: '6' |
| 133 | + click_on 'Filter' |
| 134 | + page.should_not have_content('Quick Brown Fox') |
67 | 135 |
|
68 |
| - fill_in 'Search Title', with: '' |
69 |
| - click_on 'Filter' |
| 136 | + within '.filter_numeric' do |
| 137 | + find(:select).find('option[value=view_count_lt]').select_option |
| 138 | + end |
| 139 | + click_on 'Filter' |
70 | 140 |
|
71 |
| - page.should have_content('Displaying 1 Post') |
| 141 | + within '#index_table_posts' do |
| 142 | + page.should have_content('Quick Brown Fox') |
| 143 | + end |
| 144 | + |
| 145 | + within '.filter_numeric' do |
| 146 | + find(:select).find('option[value=view_count_gt]').select_option |
| 147 | + end |
| 148 | + click_on 'Filter' |
| 149 | + page.should_not have_content('Quick Brown Fox') |
| 150 | + |
| 151 | + fill_in 'View count', with: '4' |
| 152 | + click_on 'Filter' |
| 153 | + |
| 154 | + within '#index_table_posts' do |
| 155 | + page.should have_content('Quick Brown Fox') |
| 156 | + end |
| 157 | + |
| 158 | + fill_in 'View count', with: '' |
| 159 | + click_on 'Filter' |
| 160 | + |
| 161 | + page.should have_content('Displaying 1 Post') |
| 162 | + end |
| 163 | + end |
| 164 | + end |
| 165 | + |
| 166 | + describe 'select' do |
| 167 | + it 'selects by admin_user' do |
| 168 | + select email, from: 'Admin user' |
| 169 | + click_on 'Filter' |
| 170 | + |
| 171 | + within '#index_table_posts' do |
| 172 | + page.should have_content('Quick Brown Fox') |
| 173 | + end |
| 174 | + |
| 175 | + select other_email, from: 'Admin user' |
| 176 | + click_on 'Filter' |
| 177 | + page.should_not have_content('Quick Brown Fox') |
| 178 | + |
| 179 | + select 'Any', from: 'Admin user' |
| 180 | + click_on 'Filter' |
| 181 | + |
| 182 | + page.should have_content('Displaying 1 Post') |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + describe 'check_boxes' do |
| 187 | + it 'checks by other_user' do |
| 188 | + check email |
| 189 | + click_on 'Filter' |
| 190 | + page.should_not have_content('Quick Brown Fox') |
| 191 | + |
| 192 | + check other_email |
| 193 | + click_on 'Filter' |
| 194 | + |
| 195 | + within '#index_table_posts' do |
| 196 | + page.should have_content('Quick Brown Fox') |
| 197 | + end |
| 198 | + |
| 199 | + uncheck email |
| 200 | + uncheck other_email |
| 201 | + click_on 'Filter' |
| 202 | + |
| 203 | + page.should have_content('Displaying 1 Post') |
| 204 | + end |
| 205 | + end |
| 206 | + |
| 207 | + end |
72 | 208 | end
|
| 209 | + |
73 | 210 | end
|
0 commit comments