date_book 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DateBook
4
+ # Some documentation goes here
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace DateBook
7
+ engine_name 'date_book'
8
+
9
+ config.generators do |g|
10
+ g.hidden_namespaces << 'test_unit' << 'erb'
11
+ g.orm :active_record
12
+ g.template_engine :haml
13
+ g.test_framework :rspec, fixture: false
14
+ g.integration_tool :rspec
15
+ g.stylesheets false
16
+ g.javascripts false
17
+ g.view_specs false
18
+ g.helper_specs false
19
+ end
20
+
21
+ initializer 'date_book.assets.precompile' do |app|
22
+ app.config.assets.precompile += %w(
23
+ date_book.js date_book.css bootstrap-wysiwyg/bootstrap-wysiwyg.css
24
+ bootstrap-wysiwyg.js jquery_nested_form.js jquery_nested_form.js
25
+ bootstrap-datetimepicker.js bootstrap-datetimepicker.css
26
+ )
27
+ end
28
+
29
+ initializer "date_book.add_middleware" do |app|
30
+ app.config.middleware.insert_before 0, Rack::Cors do
31
+ allow do
32
+ origins %r{\Ahttp://localhost:3000\z}
33
+ resource '*', :headers => :any, :methods => [:get, :post, :options]
34
+ end
35
+ end
36
+
37
+ app.config.middleware.insert_before Warden::Manager, Rack::Cors
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # String Extension
4
+ module StringExtension
5
+ def localize(*args)
6
+ sym = if args.first.is_a? Symbol
7
+ args.shift
8
+ else
9
+ underscore.tr(' ', '_').gsub(/[^a-z0-9_]+/i, '').to_sym
10
+ end
11
+ args << { default: self }
12
+
13
+ I18n.t(sym, *args).html_safe
14
+ end
15
+ alias l localize
16
+ end
17
+ String.send :include, StringExtension
18
+
19
+ # Symbol Extensions
20
+ module SymbolExtensionCustom
21
+ def localize_with_debugging(*args)
22
+ localized_sym = I18n.translate(self, *args)
23
+ localized_sym.is_a?(String) ? localized_sym.html_safe : localized_sym
24
+ end
25
+ alias l localize_with_debugging
26
+
27
+ def l_with_args(*args)
28
+ l(*args).html_safe
29
+ end
30
+ end
31
+
32
+ Symbol.send :include, SymbolExtensionCustom
@@ -0,0 +1,8 @@
1
+ # Message Train module
2
+ module DateBook
3
+ VERSION = File.read(File.expand_path('../../../VERSION', __FILE__))
4
+
5
+ def self.version_string
6
+ "DateBook version #{DateBook::VERSION}"
7
+ end
8
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DateBook
4
+ # DateBook Install Generator
5
+ class InstallGenerator < Rails::Generators::Base
6
+ argument :user_model_name, type: :string, default: 'User'
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ require File.expand_path('../../utils', __FILE__)
9
+ include Generators::Utils
10
+ include Rails::Generators::Migration
11
+
12
+ def hello
13
+ output 'DateBook Installer will now install itself', :magenta
14
+ end
15
+
16
+ # all public methods in here will be run in order
17
+
18
+ def install_devise
19
+ output(
20
+ 'To start with, Devise is used to authenticate users. No need to '\
21
+ "install it separately, I'll do that now.", :magenta
22
+ )
23
+ generate('devise:install')
24
+ generate('devise User')
25
+ end
26
+
27
+ def install_cancan
28
+ output(
29
+ "For authorization, DateBook uses CanCanCan. Let's get you started "\
30
+ 'with a customizable ability.rb file.',
31
+ :magenta
32
+ )
33
+ template 'app/models/ability.rb', 'app/models/ability.rb'
34
+ end
35
+
36
+ def install_rolify
37
+ output(
38
+ "To provide varying roles for Users, we'll use Rolify. Let's set that "\
39
+ 'up now.',
40
+ :magenta
41
+ )
42
+ generate('rolify', 'Role User')
43
+ end
44
+
45
+ def install_bootstrap_leather
46
+ output(
47
+ 'To make building in bootstrap easier, we use Bootstrap Leather.',
48
+ :magenta
49
+ )
50
+ generate('bootstrap_leather:install')
51
+ end
52
+
53
+ def add_initializer
54
+ output(
55
+ "Next, you'll need an initializer for Date Book.",
56
+ :magenta
57
+ )
58
+ template 'config/initializers/date_book.rb', 'config/initializers/date_book.rb'
59
+ end
60
+
61
+ def add_models
62
+ output(
63
+ 'Models for you to extend will be placed in your models directory',
64
+ :magenta
65
+ )
66
+ template 'app/models/calendar.rb', 'app/models/calendar.rb'
67
+ template 'app/models/event.rb', 'app/models/event.rb'
68
+ template 'app/models/event_occurrence.rb', 'app/models/event_occurrence.rb'
69
+ template 'app/models/schedule.rb', 'app/models/schedule.rb'
70
+ end
71
+
72
+ def add_to_user
73
+ output 'Adding DateBook to your User model', :magenta
74
+ gsub_file(
75
+ 'app/models/user.rb',
76
+ %r{acts_as_owner},
77
+ ''
78
+ )
79
+ inject_into_file 'app/models/user.rb', after: "rolify\n" do
80
+ <<-'RUBY'
81
+ acts_as_owner
82
+ RUBY
83
+ end
84
+ end
85
+
86
+ def add_migrations
87
+ output 'Next come migrations.', :magenta
88
+ rake 'date_book:install:migrations'
89
+ end
90
+
91
+ # def add_to_model
92
+ # output 'Adding DateBook to your User model', :magenta
93
+ # gsub_file 'app/models/user.rb', /^\n subscriber$/, ''
94
+ # inject_into_file(
95
+ # 'app/models/user.rb', "\n subscriber",
96
+ # after: 'class User < ActiveRecord::Base'
97
+ # )
98
+ # end
99
+
100
+ def add_route
101
+ output 'Adding DateBook to your routes.rb file', :magenta
102
+ gsub_file(
103
+ 'config/routes.rb',
104
+ %r{mount DateBook::Engine => '/.*', as: 'date_book'},
105
+ ''
106
+ )
107
+ route("mount DateBook::Engine => '/date_book', as: 'date_book'")
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # CanCanCan Ability class
4
+ class Ability
5
+ include CanCan::Ability
6
+ include DateBook::Ability
7
+
8
+ def initialize(user)
9
+ user ||= User.new # anonymous user (not logged in)
10
+
11
+ # Rails Application's initialization could go here.
12
+ # can :manage, Group, user: user
13
+
14
+ initialize_date_book(user)
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class Calendar < ApplicationRecord
2
+ acts_as_calendar
3
+ end
@@ -0,0 +1,3 @@
1
+ class Event < ApplicationRecord
2
+ acts_as_event
3
+ end
@@ -0,0 +1,3 @@
1
+ class EventOccurrence < ApplicationRecord
2
+ acts_as_event_occurrence
3
+ end
@@ -0,0 +1,3 @@
1
+ class Schedule < Schedulable::Model::Schedule
2
+ acts_as_schedule
3
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ DateBook.configure do |config|
4
+ config.week_starts_on = 'Sunday'
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DateBook
4
+ module Generators
5
+ # Generator Utilities
6
+ module Utils
7
+ def output(output, color = :green)
8
+ say(" - #{output}", color)
9
+ end
10
+
11
+ def ask_for(wording, default_value = nil, override_if_present_value = nil)
12
+ if override_if_present_value.present?
13
+ display(
14
+ "Using [#{override_if_present_value}] for question '#{wording}'"
15
+ ) && override_if_present_value
16
+ else
17
+ ask(
18
+ " ? #{wording} Press <enter> for [#{default_value}] >",
19
+ :yellow
20
+ ).presence || default_value
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :date_book do
4
+ # # Task goes here
5
+ # end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+ require 'cancan/matchers'
5
+
6
+ describe 'Abilities on Calendars', folder: :abilities do
7
+ include_context 'loaded site'
8
+
9
+ ####################
10
+ # Abilities #
11
+ ####################
12
+ context 'when anonymous' do
13
+ let(:user) { nil }
14
+ subject(:ability) { Ability.new(user) }
15
+ it { should be_able_to(:index, regular_calendar) }
16
+ it { should be_able_to(:show, regular_calendar) }
17
+ it { should_not be_able_to(:manage, regular_calendar) }
18
+ it { should_not be_able_to(:create, Calendar) }
19
+ end
20
+ context 'when logged in as regular user' do
21
+ let(:user) { regular_user }
22
+ subject(:ability) { Ability.new(user) }
23
+ it { should be_able_to(:index, regular_calendar) }
24
+ it { should be_able_to(:show, regular_calendar) }
25
+ it { should be_able_to(:manage, regular_calendar) }
26
+ it { should be_able_to(:create, Calendar) }
27
+ it { should be_able_to(:index, other_calendar) }
28
+ it { should be_able_to(:show, other_calendar) }
29
+ it { should_not be_able_to(:manage, other_calendar) }
30
+ end
31
+ context 'when logged in as admin' do
32
+ let(:user) { admin_user }
33
+ subject(:ability) { Ability.new(user) }
34
+ it { should be_able_to(:index, regular_calendar) }
35
+ it { should be_able_to(:show, regular_calendar) }
36
+ it { should be_able_to(:manage, regular_calendar) }
37
+ it { should be_able_to(:create, Calendar) }
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+ require 'cancan/matchers'
5
+
6
+ describe 'Abilities on Events', folder: :abilities do
7
+ include_context 'loaded site'
8
+
9
+ ####################
10
+ # Abilities #
11
+ ####################
12
+ context 'when anonymous' do
13
+ let(:event) { monday_event }
14
+ let(:user) { nil }
15
+ subject(:ability) { Ability.new(user) }
16
+ it { should be_able_to(:index, event) }
17
+ it { should be_able_to(:show, event) }
18
+ it { should_not be_able_to(:manage, event) }
19
+ it { should_not be_able_to(:create, Event) }
20
+ end
21
+ context 'when logged in as regular user' do
22
+ let(:my_event) { science_fiction_club_event }
23
+ let(:other_event) { monday_event }
24
+ let(:user) { regular_user }
25
+ subject(:ability) { Ability.new(user) }
26
+ it { should be_able_to(:index, my_event) }
27
+ it { should be_able_to(:show, my_event) }
28
+ it { should be_able_to(:manage, my_event) }
29
+ it { should be_able_to(:create, regular_calendar.events.new) }
30
+ it { should be_able_to(:index, other_event) }
31
+ it { should be_able_to(:show, other_event) }
32
+ it { should_not be_able_to(:manage, other_event) }
33
+ it { should_not be_able_to(:create, other_calendar.events.new) }
34
+ end
35
+ context 'when logged in as admin' do
36
+ let(:event) { monday_event }
37
+ let(:user) { admin_user }
38
+ subject(:ability) { Ability.new(user) }
39
+ it { should be_able_to(:index, event) }
40
+ it { should be_able_to(:show, event) }
41
+ it { should be_able_to(:manage, event) }
42
+ it { should be_able_to(:create, Event) }
43
+ end
44
+ end
@@ -0,0 +1,259 @@
1
+ require 'rails_helper'
2
+
3
+ module DateBook
4
+ RSpec.describe CalendarsController, folder: :controllers do
5
+ routes { DateBook::Engine.routes }
6
+
7
+ include_context 'loaded site'
8
+ include ControllerMacros
9
+
10
+ # This should return the minimal set of attributes required to create a valid
11
+ # Calendar. As you add validations to Calendar, be sure to
12
+ # adjust the attributes here as well.
13
+ let(:valid_attributes) {
14
+ { name: 'Test Calendar', schedule_attributes: { date: 1.hour.ago.to_date, time: 1.hour.ago} }
15
+ }
16
+
17
+ let(:invalid_attributes) {
18
+ { name: nil, schedule_attributes: nil }
19
+ }
20
+
21
+ describe 'GET #index' do
22
+ before do
23
+ get :index, params: {}
24
+ end
25
+ it_should_behave_like 'a successful page', which_renders: 'index'
26
+
27
+ describe 'loads calendars into @calendars' do
28
+ subject { assigns(:calendars) }
29
+ it { should include regular_calendar }
30
+ it { should include other_calendar }
31
+ it { should include admin_calendar }
32
+ end
33
+ end
34
+
35
+ describe 'GET #show' do
36
+ before do
37
+ get :show, params: { id: 'regular-calendar' }
38
+ end
39
+ it_should_behave_like 'a successful page', which_renders: 'show'
40
+ end
41
+
42
+ describe 'GET #new' do
43
+ describe 'when not logged in' do
44
+ before do
45
+ # Here's where we are *not* logging in
46
+ get :new
47
+ end
48
+ it_should_behave_like 'a redirect to the home page'
49
+ end
50
+ describe 'when logged in' do
51
+ before do
52
+ login_user regular_user
53
+ get :new
54
+ end
55
+ it_should_behave_like 'a successful page', which_renders: 'new'
56
+
57
+ describe 'loads a new calendar into @calendar' do
58
+ subject { assigns(:calendar) }
59
+ it { should be_a_new Calendar }
60
+ end
61
+ end
62
+ end
63
+
64
+ describe 'GET #edit' do
65
+ describe 'when not logged in' do
66
+ before do
67
+ # Here's where we are *not* logging in
68
+ get :edit, params: { id: 'regular-calendar' }
69
+ end
70
+ it_should_behave_like 'a redirect to the home page'
71
+ end
72
+ describe 'when logged in' do
73
+ describe 'as someone other than the owner' do
74
+ before do
75
+ login_user other_user
76
+ get :edit, params: { id: 'regular-calendar' }
77
+ end
78
+ it_should_behave_like 'a 403 Forbidden error'
79
+ end
80
+ describe 'as the owner' do
81
+ before do
82
+ login_user regular_user
83
+ get :edit, params: { id: 'regular-calendar' }
84
+ end
85
+ it_should_behave_like 'a successful page', which_renders: 'edit'
86
+
87
+ describe 'loads requested calendar into @calendar' do
88
+ subject { assigns(:calendar) }
89
+ it { should eq regular_calendar }
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ describe 'POST #create' do
97
+ describe 'when not logged in' do
98
+ before do
99
+ # Here's where we are *not* logging in
100
+ post :create, params: { calendar: valid_attributes }
101
+ end
102
+ it_should_behave_like 'a redirect to the home page'
103
+ end
104
+ describe 'when logged in' do
105
+ describe 'with valid params' do
106
+ before do
107
+ login_user regular_user
108
+ post :create, params: { calendar: valid_attributes }
109
+ end
110
+ it_should_behave_like(
111
+ 'a redirect to',
112
+ '/date_book/calendars/test-calendar'
113
+ )
114
+ describe "sets the flash with a notice of the calendar's creation" do
115
+ subject { flash[:notice] }
116
+ it { should eq 'Calendar was successfully created.' }
117
+ end
118
+ end
119
+ describe 'with valid params, counting' do
120
+ before do
121
+ login_user regular_user
122
+ end
123
+ it 'results in a new calendar' do
124
+ expect { post(:create, params: { calendar: valid_attributes }) }
125
+ .to change { Calendar.count(:id) }.by(1)
126
+ end
127
+ end
128
+ describe 'with invalid params' do
129
+ before do
130
+ login_user regular_user
131
+ post :create, params: { calendar: invalid_attributes }
132
+ end
133
+ it_should_behave_like 'a successful page', which_renders: 'new'
134
+
135
+ describe "sets the flash with the calendar's errors" do
136
+ subject { flash[:error] }
137
+ it { should eq "Name can't be blank" }
138
+ end
139
+ end
140
+ describe 'with invalid params, counting' do
141
+ before do
142
+ login_user regular_user
143
+ end
144
+ it 'does not result in a new calendar' do
145
+ expect { post(:create, params: { calendar: invalid_attributes }) }
146
+ .to_not change { Calendar.count(:id) }
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ describe 'PUT #update' do
153
+ describe 'when not logged in' do
154
+ before do
155
+ # Here's where we are *not* logging in
156
+ put :update, params: { id: 'regular-calendar', calendar: valid_attributes }
157
+ end
158
+ it_should_behave_like 'a redirect to the home page'
159
+ end
160
+ describe 'when logged in' do
161
+ describe 'as someone other than the owner' do
162
+ before do
163
+ login_user other_user
164
+ put :update, params: { id: 'regular-calendar', calendar: valid_attributes }
165
+ end
166
+ it_should_behave_like 'a 403 Forbidden error'
167
+ end
168
+ describe 'as the owner' do
169
+ describe 'with valid params' do
170
+ before do
171
+ login_user regular_user
172
+ put :update, params: { id: 'regular-calendar', calendar: valid_attributes }
173
+ end
174
+ # Note that slug does not change
175
+ it_should_behave_like 'a redirect to', '/date_book/calendars/regular-calendar'
176
+
177
+ describe 'updates @calendar' do
178
+ subject { regular_calendar.reload }
179
+ its(:name) { should eq 'Test Calendar' }
180
+ end
181
+
182
+ describe "sets the flash with a notice of the calendar's update" do
183
+ subject { flash[:notice] }
184
+ it { should eq 'Calendar was successfully updated.' }
185
+ end
186
+ end
187
+ describe 'with invalid params' do
188
+ before do
189
+ login_user regular_user
190
+ put(
191
+ :update, params: {
192
+ id: 'regular-calendar',
193
+ calendar: invalid_attributes
194
+ })
195
+ end
196
+ it_should_behave_like 'a successful page', which_renders: 'edit'
197
+
198
+ describe 'loads the given calendar into @calendar' do
199
+ subject { assigns(:calendar) }
200
+ it { should eq regular_calendar }
201
+ end
202
+
203
+ describe 'does not update @calendar' do
204
+ subject { regular_calendar.reload }
205
+ its(:name) { should eq 'Regular Calendar' }
206
+ end
207
+
208
+ describe "sets the flash with the calendar's errors" do
209
+ subject { flash[:error] }
210
+ it { should eq "Name can't be blank" }
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ describe 'DELETE #destroy' do
218
+ describe 'when not logged in' do
219
+ before do
220
+ # Here's where we are *not* logging in
221
+ delete :destroy, params: { id: 'regular-calendar' }
222
+ end
223
+ it_should_behave_like 'a redirect to the home page'
224
+ end
225
+ describe 'when logged in' do
226
+ describe 'as someone other than the owner' do
227
+ before do
228
+ login_user other_user
229
+ delete :destroy, params: { id: 'regular-calendar' }
230
+ end
231
+ it_should_behave_like 'a 403 Forbidden error'
232
+ end
233
+ describe 'as the owner' do
234
+ before do
235
+ login_user regular_user
236
+ delete :destroy, params: { id: 'regular-calendar' }
237
+ end
238
+ # Note that slug does not change
239
+ it_should_behave_like 'a redirect to', '/date_book/calendars'
240
+
241
+ describe "sets the flash with a notice of the calendar's removal" do
242
+ subject { flash[:notice] }
243
+ it { should eq 'Calendar was successfully removed.' }
244
+ end
245
+ end
246
+ describe 'as the owner, counting' do
247
+ before do
248
+ login_user regular_user
249
+ end
250
+ it 'results one less calendar' do
251
+ expect { delete(:destroy, params: { id: 'regular-calendar' }) }
252
+ .to change { Calendar.count(:id) }.by(-1)
253
+ end
254
+ end
255
+ end
256
+ end
257
+
258
+ end
259
+ end