date_book 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/vcs.xml +6 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +23 -0
  5. data/.rubocop_todo.yml +7 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +3 -0
  9. data/Gemfile +94 -0
  10. data/Gemfile.lock +385 -0
  11. data/LICENSE.txt +20 -0
  12. data/README.md +64 -0
  13. data/Rakefile +30 -0
  14. data/VERSION +1 -0
  15. data/app/assets/images/date_book/.keep +0 -0
  16. data/app/assets/javascripts/date_book.js +21 -0
  17. data/app/assets/javascripts/date_book/calendar_events.js +57 -0
  18. data/app/assets/javascripts/date_book/event_form.js +31 -0
  19. data/app/assets/javascripts/date_book/popovers.js +3 -0
  20. data/app/assets/javascripts/date_book/wysiwyg.js +8 -0
  21. data/app/assets/stylesheets/date_book.css.scss +46 -0
  22. data/app/controllers/date_book/calendars_controller.rb +60 -0
  23. data/app/controllers/date_book/date_book_controller.rb +24 -0
  24. data/app/controllers/date_book/events_controller.rb +105 -0
  25. data/app/controllers/date_book/graphql_controller.rb +35 -0
  26. data/app/graphql/date_book_schema.rb +18 -0
  27. data/app/graphql/types/calendar_type.rb +14 -0
  28. data/app/graphql/types/date_time_type.rb +7 -0
  29. data/app/graphql/types/event_occurrence_type.rb +11 -0
  30. data/app/graphql/types/event_type.rb +19 -0
  31. data/app/graphql/types/mutation_type.rb +5 -0
  32. data/app/graphql/types/profile_type.rb +7 -0
  33. data/app/graphql/types/query_type.rb +57 -0
  34. data/app/helpers/date_book/application_helper.rb +35 -0
  35. data/app/helpers/date_book/calendar_helper.rb +4 -0
  36. data/app/helpers/date_book/events_helper.rb +42 -0
  37. data/app/jobs/date_book/application_job.rb +6 -0
  38. data/app/mailers/date_book/application_mailer.rb +9 -0
  39. data/app/views/date_book/application/_all_day_checkbox.html.haml +1 -0
  40. data/app/views/date_book/application/_date_range.html.haml +8 -0
  41. data/app/views/date_book/application/_wysiwyg.html.haml +65 -0
  42. data/app/views/date_book/calendars/_form.html.haml +6 -0
  43. data/app/views/date_book/calendars/edit.html.haml +5 -0
  44. data/app/views/date_book/calendars/index.html.haml +28 -0
  45. data/app/views/date_book/calendars/new.html.haml +5 -0
  46. data/app/views/date_book/calendars/show.html.haml +28 -0
  47. data/app/views/date_book/events/_event.json.jbuilder +12 -0
  48. data/app/views/date_book/events/_form.html.haml +16 -0
  49. data/app/views/date_book/events/_occurrence_dates.html.haml +11 -0
  50. data/app/views/date_book/events/edit.html.haml +5 -0
  51. data/app/views/date_book/events/fields/_date.html.haml +1 -0
  52. data/app/views/date_book/events/fields/_day.html.haml +1 -0
  53. data/app/views/date_book/events/fields/_day_of_week.html.haml +19 -0
  54. data/app/views/date_book/events/fields/_duration.html.haml +6 -0
  55. data/app/views/date_book/events/fields/_interval.html.haml +1 -0
  56. data/app/views/date_book/events/fields/_time.html.haml +1 -0
  57. data/app/views/date_book/events/index.html.haml +16 -0
  58. data/app/views/date_book/events/new.html.haml +5 -0
  59. data/app/views/date_book/events/popover.html.haml +7 -0
  60. data/app/views/date_book/events/rules/_daily.html.haml +4 -0
  61. data/app/views/date_book/events/rules/_monthly.html.haml +5 -0
  62. data/app/views/date_book/events/rules/_singular.html.haml +4 -0
  63. data/app/views/date_book/events/rules/_weekly.html.haml +5 -0
  64. data/app/views/date_book/events/show.html.haml +16 -0
  65. data/app/views/layouts/_date_book_scripts.html.haml +4 -0
  66. data/app/views/layouts/blank.html.haml +1 -0
  67. data/bin/rails +15 -0
  68. data/config/locales/en.yml +44 -0
  69. data/config/routes.rb +12 -0
  70. data/date_book.gemspec +337 -0
  71. data/db/migrate/20170807133845_create_calendars.rb +11 -0
  72. data/db/migrate/20170807133846_create_events.rb +20 -0
  73. data/db/migrate/20170807133847_create_schedules.rb +25 -0
  74. data/db/migrate/20170807133848_add_fields_to_schedule.rb +6 -0
  75. data/db/migrate/20170807133849_create_event_occurrences.rb +16 -0
  76. data/db/migrate/20170807133850_add_fields_to_event_occurrences.rb +5 -0
  77. data/lib/date_book.rb +40 -0
  78. data/lib/date_book/concerns/ability.rb +27 -0
  79. data/lib/date_book/concerns/acts_as_calendar.rb +29 -0
  80. data/lib/date_book/concerns/acts_as_event.rb +66 -0
  81. data/lib/date_book/concerns/acts_as_event_occurrence.rb +67 -0
  82. data/lib/date_book/concerns/acts_as_ownable.rb +29 -0
  83. data/lib/date_book/concerns/acts_as_owner.rb +18 -0
  84. data/lib/date_book/concerns/acts_as_schedule.rb +44 -0
  85. data/lib/date_book/configuration.rb +43 -0
  86. data/lib/date_book/engine.rb +40 -0
  87. data/lib/date_book/localization.rb +32 -0
  88. data/lib/date_book/version.rb +8 -0
  89. data/lib/generators/date_book/install/install_generator.rb +110 -0
  90. data/lib/generators/date_book/install/templates/app/models/ability.rb +16 -0
  91. data/lib/generators/date_book/install/templates/app/models/calendar.rb +3 -0
  92. data/lib/generators/date_book/install/templates/app/models/event.rb +3 -0
  93. data/lib/generators/date_book/install/templates/app/models/event_occurrence.rb +3 -0
  94. data/lib/generators/date_book/install/templates/app/models/schedule.rb +3 -0
  95. data/lib/generators/date_book/install/templates/config/initializers/date_book.rb +5 -0
  96. data/lib/generators/date_book/utils.rb +25 -0
  97. data/lib/tasks/date_book_tasks.rake +5 -0
  98. data/spec/abilities/calendar_spec.rb +39 -0
  99. data/spec/abilities/event_spec.rb +44 -0
  100. data/spec/controllers/date_book/calendars_controller_spec.rb +259 -0
  101. data/spec/controllers/date_book/events_controller_spec.rb +283 -0
  102. data/spec/dummy/Rakefile +9 -0
  103. data/spec/dummy/app/assets/config/manifest.js +5 -0
  104. data/spec/dummy/app/assets/images/.keep +0 -0
  105. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  106. data/spec/dummy/app/assets/stylesheets/application.css.scss +4 -0
  107. data/spec/dummy/app/assets/stylesheets/bootstrap-everything.scss +54 -0
  108. data/spec/dummy/app/controllers/application_controller.rb +21 -0
  109. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  110. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  111. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  112. data/spec/dummy/app/models/ability.rb +16 -0
  113. data/spec/dummy/app/models/application_record.rb +5 -0
  114. data/spec/dummy/app/models/calendar.rb +3 -0
  115. data/spec/dummy/app/models/concerns/.keep +0 -0
  116. data/spec/dummy/app/models/event.rb +3 -0
  117. data/spec/dummy/app/models/event_occurrence.rb +3 -0
  118. data/spec/dummy/app/models/role.rb +13 -0
  119. data/spec/dummy/app/models/schedule.rb +3 -0
  120. data/spec/dummy/app/models/user.rb +9 -0
  121. data/spec/dummy/app/views/application/403.html.haml +9 -0
  122. data/spec/dummy/app/views/application/404.html.haml +9 -0
  123. data/spec/dummy/app/views/layouts/application.html.haml +43 -0
  124. data/spec/dummy/app/views/pages/index.html.haml +1 -0
  125. data/spec/dummy/bin/bundle +5 -0
  126. data/spec/dummy/bin/rails +6 -0
  127. data/spec/dummy/bin/rake +6 -0
  128. data/spec/dummy/bin/setup +36 -0
  129. data/spec/dummy/bin/update +31 -0
  130. data/spec/dummy/config.ru +7 -0
  131. data/spec/dummy/config/application.rb +38 -0
  132. data/spec/dummy/config/boot.rb +7 -0
  133. data/spec/dummy/config/cable.yml +9 -0
  134. data/spec/dummy/config/database.yml +25 -0
  135. data/spec/dummy/config/environment.rb +7 -0
  136. data/spec/dummy/config/environments/development.rb +60 -0
  137. data/spec/dummy/config/environments/test.rb +45 -0
  138. data/spec/dummy/config/initializers/application_controller_renderer.rb +7 -0
  139. data/spec/dummy/config/initializers/assets.rb +14 -0
  140. data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
  141. data/spec/dummy/config/initializers/bootstrap_leather.rb +9 -0
  142. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  143. data/spec/dummy/config/initializers/date_book.rb +5 -0
  144. data/spec/dummy/config/initializers/devise.rb +277 -0
  145. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  146. data/spec/dummy/config/initializers/high_voltage.rb +3 -0
  147. data/spec/dummy/config/initializers/inflections.rb +17 -0
  148. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  149. data/spec/dummy/config/initializers/new_framework_defaults.rb +29 -0
  150. data/spec/dummy/config/initializers/rolify.rb +7 -0
  151. data/spec/dummy/config/initializers/session_store.rb +5 -0
  152. data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
  153. data/spec/dummy/config/locales/devise.en.yml +64 -0
  154. data/spec/dummy/config/locales/en.yml +23 -0
  155. data/spec/dummy/config/puma.rb +49 -0
  156. data/spec/dummy/config/routes.rb +15 -0
  157. data/spec/dummy/config/secrets.yml +22 -0
  158. data/spec/dummy/config/spring.rb +8 -0
  159. data/spec/dummy/db/migrate/20170728171103_create_users_table.rb +7 -0
  160. data/spec/dummy/db/migrate/20170807134122_add_devise_to_users.rb +49 -0
  161. data/spec/dummy/db/migrate/20170807134128_rolify_create_roles.rb +19 -0
  162. data/spec/dummy/db/migrate/20170807134137_create_calendars.date_book.rb +12 -0
  163. data/spec/dummy/db/migrate/20170807134138_create_events.date_book.rb +21 -0
  164. data/spec/dummy/db/migrate/20170807134139_create_schedules.date_book.rb +26 -0
  165. data/spec/dummy/db/migrate/20170807134140_add_fields_to_schedule.date_book.rb +7 -0
  166. data/spec/dummy/db/migrate/20170807134141_create_event_occurrences.date_book.rb +17 -0
  167. data/spec/dummy/db/migrate/20170807134142_add_fields_to_event_occurrences.date_book.rb +6 -0
  168. data/spec/dummy/db/schema.rb +101 -0
  169. data/spec/dummy/db/seeds.rb +0 -0
  170. data/spec/dummy/db/seeds/calendars.seeds.rb +22 -0
  171. data/spec/dummy/db/seeds/events.seeds.rb +89 -0
  172. data/spec/dummy/db/seeds/users.seeds.rb +16 -0
  173. data/spec/dummy/lib/assets/.keep +0 -0
  174. data/spec/dummy/lib/basic_benchmark.rb +9 -0
  175. data/spec/dummy/log/.keep +0 -0
  176. data/spec/factories/calendars.rb +11 -0
  177. data/spec/factories/events.rb +12 -0
  178. data/spec/factories/roles.rb +5 -0
  179. data/spec/factories/users.rb +9 -0
  180. data/spec/features/calendars_spec.rb +185 -0
  181. data/spec/features/events_spec.rb +201 -0
  182. data/spec/helpers/date_book/calendar_helper_spec.rb +17 -0
  183. data/spec/helpers/date_book/events_helper_spec.rb +17 -0
  184. data/spec/models/calendar_spec.rb +26 -0
  185. data/spec/models/event_spec.rb +67 -0
  186. data/spec/models/role_spec.rb +5 -0
  187. data/spec/rails_helper.rb +116 -0
  188. data/spec/requests/date_book/events_spec.rb +56 -0
  189. data/spec/routing/date_book/calendars_routing_spec.rb +49 -0
  190. data/spec/routing/date_book/events_routing_spec.rb +54 -0
  191. data/spec/spec_helper.rb +102 -0
  192. data/spec/support/controller_behaviors.rb +101 -0
  193. data/spec/support/controller_macros.rb +25 -0
  194. data/spec/support/factory_girl.rb +3 -0
  195. data/spec/support/feature_behaviors.rb +150 -0
  196. data/spec/support/loaded_site.rb +5 -0
  197. data/spec/support/loaded_site/calendars.rb +5 -0
  198. data/spec/support/loaded_site/events.rb +6 -0
  199. data/spec/support/loaded_site/users.rb +5 -0
  200. data/spec/support/request_behaviors.rb +89 -0
  201. data/spec/support/shared_connection.rb +14 -0
  202. data/spec/support/utilities.rb +53 -0
  203. metadata +817 -0
@@ -0,0 +1,16 @@
1
+ BasicBenchmark.new "Seeding #{Rails.env} Users" do
2
+ FactoryGirl.create(
3
+ :user,
4
+ name: 'Admin User'
5
+ ).add_role(:admin)
6
+
7
+ FactoryGirl.create(
8
+ :user,
9
+ name: 'Regular User'
10
+ )
11
+
12
+ FactoryGirl.create(
13
+ :user,
14
+ name: 'Other User'
15
+ )
16
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ ### My little tool for benchmarking code blocks
2
+ class BasicBenchmark
3
+ def initialize(label)
4
+ time = Time.now
5
+ puts "--> #{label}"
6
+ yield
7
+ puts "======= Completed in #{(Time.now - time)} s ======="
8
+ end
9
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ FactoryGirl.define do
2
+ factory :calendar do
3
+ description { "<p>#{Faker::Lorem.paragraphs(2).join('</p><p>')}</p>" }
4
+ transient do
5
+ owner { User.find_by_name('Admin User') }
6
+ end
7
+ after(:create) do |record, evaluator|
8
+ evaluator.owner.add_role(:owner, record)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ FactoryGirl.define do
2
+ factory :event do
3
+ description { "<p>#{Faker::Lorem.paragraphs(2).join('</p><p>')}</p>" }
4
+ calendar { Calendar.friendly.find('admin-calendar') }
5
+ transient do
6
+ owner { User.find_by_name('Admin User') }
7
+ end
8
+ after(:create) do |record, evaluator|
9
+ evaluator.owner.add_role(:owner, record)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :role do
3
+
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ sequence :email do |n|
4
+ "test#{n}@example.com"
5
+ end
6
+ password 'password'
7
+ password_confirmation 'password'
8
+ end
9
+ end
@@ -0,0 +1,185 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.feature 'Calendars', folder: :features do
4
+ include_context 'loaded site'
5
+
6
+ include ActionView::Helpers::TextHelper
7
+ let(:paragraphs) { %w(first second) }
8
+ let!(:id) { regular_calendar.id }
9
+
10
+ describe 'Browsing Calendars' do
11
+ describe 'at /date_book/calendars' do
12
+ before do
13
+ # While we're not logged in:
14
+ visit '/date_book/calendars'
15
+ end
16
+ it_behaves_like 'a bootstrap page showing an item', Calendar, 'Calendars'
17
+ end
18
+ end
19
+
20
+ describe 'Showing Calendars' do
21
+ describe 'at /date_book/calendars/regular-calendar' do
22
+ before do
23
+ visit '/date_book/calendars/regular-calendar'
24
+ end
25
+ it_behaves_like 'a bootstrap page showing an item', Calendar, 'Regular Calendar'
26
+ end
27
+ end
28
+
29
+ describe 'Adding and Editing Calendars', js: true do
30
+ describe 'Adding' do
31
+ describe 'when not logged in' do
32
+ before do
33
+ # While we're not logged in:
34
+ visit '/date_book/calendars/new'
35
+ end
36
+ it_behaves_like 'an authentication error'
37
+ end
38
+ describe 'when logged in' do
39
+ before do
40
+ login_as regular_user
41
+ visit '/date_book/calendars/new'
42
+ end
43
+ it_behaves_like 'a bootstrap page', title: 'New Calendar'
44
+ describe 'displays a form to add a new Calendar' do
45
+ subject { page }
46
+ it { should have_css('form#new_calendar') }
47
+ it { should have_field('Name') }
48
+ it { should have_text('Description') }
49
+ end
50
+ describe 'validates adding a Calendar' do
51
+ before do
52
+ fill_in 'Name', with: ''
53
+ click_button 'Save Calendar'
54
+ end
55
+ subject { page }
56
+ it_behaves_like(
57
+ 'a bootstrap page with an alert',
58
+ 'danger',
59
+ "Name can't be blank"
60
+ )
61
+ it 'shows errors on name' do
62
+ expect(page.has_css?('[id$=name]')).to be true
63
+ end
64
+ end
65
+ describe 'permits adding a valid Calendar', js: true do
66
+ before do
67
+ fill_in 'Name', with: 'Calendar Name Here'
68
+ fill_in_wysiwyg(
69
+ 'Description',
70
+ simple_format(paragraphs.join("\n\n"))
71
+ )
72
+ click_button 'Save Calendar'
73
+ end
74
+ it_behaves_like(
75
+ 'a bootstrap page with an alert',
76
+ 'info',
77
+ 'Calendar was successfully created.'
78
+ )
79
+ it_behaves_like 'a bootstrap page', title: 'Calendar Name Here'
80
+ end
81
+ end
82
+ end
83
+ describe 'Editing' do
84
+ describe 'when not logged in' do
85
+ before do
86
+ # While we're not logged in:
87
+ visit '/date_book/calendars/regular-calendar/edit'
88
+ end
89
+ it_behaves_like 'an authentication error'
90
+ end
91
+ describe 'when logged in' do
92
+ describe 'and not authorized' do
93
+ before do
94
+ login_as other_user
95
+ visit '/date_book/calendars/regular-calendar/edit'
96
+ end
97
+ it_behaves_like 'an authorization error'
98
+ end
99
+ describe 'and authorized' do
100
+ before do
101
+ login_as regular_user
102
+ visit '/date_book/calendars/regular-calendar/edit'
103
+ end
104
+ it_behaves_like 'a bootstrap page', title: 'Editing Regular Calendar'
105
+ describe 'displays a form to edit the Calendar' do
106
+ subject { page }
107
+ it { should have_css("form#edit_calendar_#{id}") }
108
+ it { should have_field('Name') }
109
+ it { should have_text('Description') }
110
+ end
111
+ describe 'validates editing a Calendar' do
112
+ before do
113
+ fill_in 'Name', with: ''
114
+ click_button 'Save Calendar'
115
+ end
116
+ it_behaves_like(
117
+ 'a bootstrap page with an alert',
118
+ 'danger',
119
+ "Name can't be blank"
120
+ )
121
+ it 'shows errors on name' do
122
+ expect(page.has_css?('[id$=name]')).to be true
123
+ end
124
+ end
125
+ describe 'permits editing a valid Calendar' do
126
+ before do
127
+ fill_in 'Name', with: 'Calendar Name Here'
128
+ fill_in_wysiwyg(
129
+ 'Description',
130
+ simple_format(paragraphs.join("\n\n"))
131
+ )
132
+ click_button 'Save Calendar'
133
+ end
134
+ it_behaves_like(
135
+ 'a bootstrap page with an alert',
136
+ 'info',
137
+ 'Calendar was successfully updated.'
138
+ )
139
+ it_behaves_like 'a bootstrap page', title: 'Calendar Name Here'
140
+ describe 'parses the description correctly' do
141
+ subject { page }
142
+ it { should have_selector 'p', text: paragraphs.first }
143
+ it { should have_selector 'p', text: paragraphs.second }
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ describe 'Removing Calendars' do
152
+ describe 'when not logged in' do
153
+ before do
154
+ # While we're not logged in:
155
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar', {}
156
+ end
157
+ it_behaves_like 'an authentication error'
158
+ end
159
+ describe 'when logged in' do
160
+ describe 'and not authorized' do
161
+ before do
162
+ login_as other_user
163
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar', {}
164
+ end
165
+ it_behaves_like 'an authorization error'
166
+ end
167
+ describe 'and authorized' do
168
+ before do
169
+ login_as regular_user
170
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar', {}
171
+ end
172
+ it_behaves_like 'a bootstrap page', title: 'Calendars'
173
+ it_behaves_like(
174
+ 'a bootstrap page with an alert',
175
+ 'info',
176
+ 'Calendar was successfully removed.'
177
+ )
178
+ describe 'does not show the removed calendar' do
179
+ subject { page }
180
+ it { should_not have_selector "#calendar-#{id}" }
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,201 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.feature 'Events', folder: :features do
4
+ include_context 'loaded site'
5
+
6
+ include ActionView::Helpers::TextHelper
7
+ let(:paragraphs) { %w(first second) }
8
+ let!(:club_id) { science_fiction_club_event.id }
9
+
10
+ describe 'Browsing Events' do
11
+ describe 'at /date_book/calendars/admin-calendar/events' do
12
+ describe 'without a query' do
13
+ before do
14
+ # While we're not logged in:
15
+ visit '/date_book/calendars/admin-calendar/events'
16
+ end
17
+ it_behaves_like(
18
+ 'a bootstrap page listing a collection of items',
19
+ Event,
20
+ minimum: 5
21
+ )
22
+ end
23
+ describe 'with a query' do
24
+ before do
25
+ visit "/date_book/calendars/admin-calendar/events?start=#{Date.today}"
26
+ end
27
+ it_behaves_like(
28
+ 'a bootstrap page listing a collection of items',
29
+ Event,
30
+ minimum: 4
31
+ )
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'Showing Events' do
37
+ describe 'at /date_book/calendars/other-calendar/events/monday' do
38
+ before do
39
+ visit '/date_book/calendars/other-calendar/events/monday'
40
+ end
41
+ it_behaves_like 'a bootstrap page showing an item', Event, 'Monday'
42
+ end
43
+ end
44
+
45
+ describe 'Adding and Editing Events', js: true do
46
+ describe 'Adding' do
47
+ describe 'when not logged in' do
48
+ before do
49
+ # While we're not logged in:
50
+ visit '/date_book/calendars/regular-calendar/events/new'
51
+ end
52
+ it_behaves_like 'an authentication error'
53
+ end
54
+ describe 'when logged in' do
55
+ before do
56
+ login_as regular_user
57
+ visit '/date_book/calendars/regular-calendar/events/new'
58
+ end
59
+ it_behaves_like 'a bootstrap page', title: 'New Event'
60
+ describe 'displays a form to add a new Event' do
61
+ subject { page }
62
+ it { should have_css('form#new_event') }
63
+ it { should have_field('Name') }
64
+ it { should have_text('Description') }
65
+ end
66
+ describe 'validates adding a Event' do
67
+ before do
68
+ fill_in 'Name', with: ''
69
+ click_button 'Save Event'
70
+ end
71
+ subject { page }
72
+ it_behaves_like(
73
+ 'a bootstrap page with an alert',
74
+ 'danger',
75
+ "Name can't be blank"
76
+ )
77
+ it 'shows errors on name' do
78
+ expect(page.has_css?('[id$=name]')).to be true
79
+ end
80
+ end
81
+ describe 'permits adding a valid Event', js: true do
82
+ before do
83
+ fill_in 'Name', with: 'Event Name Here'
84
+ fill_in_wysiwyg(
85
+ 'Description',
86
+ simple_format(paragraphs.join("\n\n"))
87
+ )
88
+ click_button 'Save Event'
89
+ end
90
+ it_behaves_like(
91
+ 'a bootstrap page with an alert',
92
+ 'info',
93
+ 'Event was successfully created.'
94
+ )
95
+ it_behaves_like 'a bootstrap page', title: 'Event Name Here'
96
+ end
97
+ end
98
+ end
99
+ describe 'Editing' do
100
+ describe 'when not logged in' do
101
+ before do
102
+ # While we're not logged in:
103
+ visit '/date_book/calendars/regular-calendar/events/science-fiction-club/edit'
104
+ end
105
+ it_behaves_like 'an authentication error'
106
+ end
107
+ describe 'when logged in' do
108
+ describe 'and not authorized' do
109
+ before do
110
+ login_as other_user
111
+ visit '/date_book/calendars/regular-calendar/events/science-fiction-club/edit'
112
+ end
113
+ it_behaves_like 'an authorization error'
114
+ end
115
+ describe 'and authorized' do
116
+ before do
117
+ login_as regular_user
118
+ visit '/date_book/calendars/regular-calendar/events/science-fiction-club/edit'
119
+ end
120
+ it_behaves_like 'a bootstrap page', title: 'Editing Science Fiction Club'
121
+ describe 'displays a form to edit the Event' do
122
+ subject { page }
123
+ it { should have_css("form#edit_event_#{club_id}") }
124
+ it { should have_field('Name') }
125
+ it { should have_text('Description') }
126
+ end
127
+ describe 'validates editing a Event' do
128
+ before do
129
+ fill_in 'Name', with: ''
130
+ click_button 'Save Event'
131
+ end
132
+ it_behaves_like(
133
+ 'a bootstrap page with an alert',
134
+ 'danger',
135
+ "Name can't be blank"
136
+ )
137
+ it 'shows errors on name' do
138
+ expect(page.has_css?('[id$=name]')).to be true
139
+ end
140
+ end
141
+ describe 'permits editing a valid Event' do
142
+ before do
143
+ fill_in 'Name', with: 'Event Name Here'
144
+ fill_in_wysiwyg(
145
+ 'Description',
146
+ simple_format(paragraphs.join("\n\n"))
147
+ )
148
+ click_button 'Save Event'
149
+ end
150
+ it_behaves_like(
151
+ 'a bootstrap page with an alert',
152
+ 'info',
153
+ 'Event was successfully updated.'
154
+ )
155
+ it_behaves_like 'a bootstrap page', title: 'Event Name Here'
156
+ describe 'parses the description correctly' do
157
+ subject { page }
158
+ it { should have_selector 'p', text: paragraphs.first }
159
+ it { should have_selector 'p', text: paragraphs.second }
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ describe 'Removing Events' do
168
+ describe 'when not logged in' do
169
+ before do
170
+ # While we're not logged in:
171
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar/events/science-fiction-club', {}
172
+ end
173
+ it_behaves_like 'an authentication error'
174
+ end
175
+ describe 'when logged in' do
176
+ describe 'and not authorized' do
177
+ before do
178
+ login_as other_user
179
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar/events/science-fiction-club', {}
180
+ end
181
+ it_behaves_like 'an authorization error'
182
+ end
183
+ describe 'and authorized' do
184
+ before do
185
+ login_as regular_user
186
+ page.driver.submit :delete, '/date_book/calendars/regular-calendar/events/science-fiction-club', {}
187
+ end
188
+ it_behaves_like 'a bootstrap page', title: 'Events'
189
+ it_behaves_like(
190
+ 'a bootstrap page with an alert',
191
+ 'info',
192
+ 'Event was successfully removed.'
193
+ )
194
+ describe 'does not show the removed event' do
195
+ subject { page }
196
+ it { should_not have_selector "#event-#{club_id}" }
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end