rails-calendar 0.2.0

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 (66) hide show
  1. data/.coveralls.yml +1 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +4 -0
  4. data/.travis.yml +12 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +14 -0
  7. data/Guardfile +5 -0
  8. data/MIT-LICENSE +21 -0
  9. data/README.md +72 -0
  10. data/Rakefile +21 -0
  11. data/lib/rails_calendar/configuration.rb +51 -0
  12. data/lib/rails_calendar/helpers.rb +7 -0
  13. data/lib/rails_calendar/simple.rb +95 -0
  14. data/lib/rails_calendar/version.rb +3 -0
  15. data/lib/rails_calendar.rb +28 -0
  16. data/lib/tasks/rails_calendar_tasks.rake +4 -0
  17. data/rails_calendar.gemspec +31 -0
  18. data/spec/dummy/README.rdoc +28 -0
  19. data/spec/dummy/Rakefile +6 -0
  20. data/spec/dummy/app/assets/images/.keep +0 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  24. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/mailers/.keep +0 -0
  27. data/spec/dummy/app/models/.keep +0 -0
  28. data/spec/dummy/app/models/concerns/.keep +0 -0
  29. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/spec/dummy/bin/bundle +3 -0
  31. data/spec/dummy/bin/rails +4 -0
  32. data/spec/dummy/bin/rake +4 -0
  33. data/spec/dummy/config/application.rb +29 -0
  34. data/spec/dummy/config/boot.rb +5 -0
  35. data/spec/dummy/config/database.yml +25 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +37 -0
  38. data/spec/dummy/config/environments/production.rb +82 -0
  39. data/spec/dummy/config/environments/test.rb +39 -0
  40. data/spec/dummy/config/initializers/assets.rb +8 -0
  41. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  43. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  44. data/spec/dummy/config/initializers/inflections.rb +16 -0
  45. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  46. data/spec/dummy/config/initializers/session_store.rb +3 -0
  47. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/spec/dummy/config/locales/en.yml +23 -0
  49. data/spec/dummy/config/routes.rb +56 -0
  50. data/spec/dummy/config/secrets.yml +22 -0
  51. data/spec/dummy/config.ru +4 -0
  52. data/spec/dummy/lib/assets/.keep +0 -0
  53. data/spec/dummy/log/.keep +0 -0
  54. data/spec/dummy/public/404.html +67 -0
  55. data/spec/dummy/public/422.html +67 -0
  56. data/spec/dummy/public/500.html +66 -0
  57. data/spec/dummy/public/favicon.ico +0 -0
  58. data/spec/rails_calendar/configuration_spec.rb +50 -0
  59. data/spec/rails_calendar/helpers_spec.rb +39 -0
  60. data/spec/rails_calendar/simple_spec.rb +271 -0
  61. data/spec/rails_calendar_spec.rb +23 -0
  62. data/spec/spec_helper.rb +84 -0
  63. data/vendor/assets/stylesheets/rails_calendar/base.css.sass +18 -0
  64. data/vendor/assets/stylesheets/rails_calendar/theme.css.sass +25 -0
  65. data/vendor/assets/stylesheets/rails_calendar.css.sass +3 -0
  66. metadata +290 -0
@@ -0,0 +1,271 @@
1
+ I18n.backend.store_translations :test,
2
+ date: {
3
+ abbr_day_names: [
4
+ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'
5
+ ]
6
+ }
7
+
8
+ I18n.locale = :test
9
+
10
+ describe RailsCalendar::Simple, type: :feature do
11
+ before do
12
+ @calendar = RailsCalendar::Simple.new Date.today
13
+ end
14
+
15
+ after do
16
+ RailsCalendar.configuration.reset!
17
+ end
18
+
19
+ describe '#initialize' do
20
+ it 'should expose the global configuration through the config variable' do
21
+ expect(@calendar.config).to be(RailsCalendar.configuration)
22
+ end
23
+ end
24
+
25
+ describe '#to_s' do
26
+ it 'should render the calendar table' do
27
+ expect(@calendar).to receive(:table).and_return('<table></table>'.html_safe)
28
+ expect(@calendar.to_s).to eq('<table></table>')
29
+ end
30
+ end
31
+
32
+ describe '#table' do
33
+ it 'should render a table concatenating the header and body' do
34
+ expect(@calendar).to receive(:header).and_return('<thead></thead>'.html_safe)
35
+ expect(@calendar).to receive(:body).and_return('<tbody></tbody>'.html_safe)
36
+
37
+ table = @calendar.send(:table)
38
+
39
+ expect(table).to have_selector('table > thead, table > tbody')
40
+ end
41
+ end
42
+
43
+ describe '#header' do
44
+ before do
45
+ @header = @calendar.send(:header)
46
+ end
47
+
48
+ it 'should render a th tag for every day of the week' do
49
+ expect(@header).to have_selector('thead > tr > th', count: 7)
50
+ end
51
+
52
+ it 'should set the names of the days in each th' do
53
+ I18n.t('date.abbr_day_names').each do |day|
54
+ expect(@header).to have_selector('th', text: day.titleize)
55
+ end
56
+ end
57
+
58
+ it 'should respect the start_of_week config' do
59
+ RailsCalendar.configuration.start_of_week = :friday
60
+ header = @calendar.send(:header)
61
+ expect(header).to have_selector('th:first-child', text: 'Fri')
62
+ end
63
+ end
64
+
65
+ describe '#body' do
66
+ context 'for every week' do
67
+ it 'should render a tr with every day rendered by day_cell' do
68
+ weeks = [
69
+ [ Date.today, 1.day.ago, 2.days.ago ],
70
+ [ 3.days.ago, 4.days.ago, 5.days.ago ]
71
+ ]
72
+
73
+ expect(@calendar).to receive(:weeks).and_return(weeks)
74
+
75
+ weeks.each do |week|
76
+ week.each do |date|
77
+ expect(@calendar).to receive(:day_cell).with(date) do
78
+ "<td>#{date.day}</td>".html_safe
79
+ end
80
+ end
81
+ end
82
+
83
+ body = @calendar.send(:body)
84
+
85
+ expect(body).to have_selector('tbody > tr', count: 2)
86
+ expect(body).to have_selector('tbody > tr > td', count: 6)
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#weeks' do
92
+ it 'should return an array of dates divided by week' do
93
+ @calendar.calendar_day = Date.strptime('2014-07-01')
94
+ weeks = @calendar.send(:weeks)
95
+
96
+ expect(weeks).to be_a(Array)
97
+
98
+ weeks.each do |week|
99
+ expect(week).to be_a(Array)
100
+ expect(week.length).to be(7)
101
+
102
+ week.each do |day|
103
+ expect(day).to be_a(Date)
104
+ end
105
+ end
106
+ end
107
+
108
+ it 'should respect the start_of_week config' do
109
+ RailsCalendar.configuration.start_of_week = :friday
110
+ @calendar.calendar_day = Date.strptime('2014-07-01')
111
+ weeks = @calendar.send(:weeks)
112
+ expect(weeks.first.first).to eq(Date.strptime('2014-06-27'))
113
+ end
114
+
115
+ it 'should always return full weeks' do
116
+ @calendar.calendar_day = Date.strptime('2014-07-01')
117
+ weeks = @calendar.send(:weeks)
118
+
119
+ expect(weeks.first.first).to eq(Date.strptime('2014-06-29'))
120
+ expect(weeks.last.last).to eq(Date.strptime('2014-08-02'))
121
+ end
122
+ end
123
+
124
+ describe '#day_cell_classes(date)' do
125
+ before do
126
+ RailsCalendar.configuration.class_prefix = 'rspec-'
127
+ RailsCalendar.configuration.day_cell_class = 'test-cell'
128
+ RailsCalendar.configuration.today_class = 'today'
129
+ end
130
+
131
+ it 'should have the class specified by day_cell_class config' do
132
+ date = Date.strptime('1900-01-20')
133
+ calendar = RailsCalendar::Simple.new(date)
134
+ cell_class = calendar.send(:day_cell_classes, date)
135
+ expect(cell_class).to eq('rspec-test-cell')
136
+ end
137
+
138
+ context 'if the date is today' do
139
+ it 'should have the class specified by today_class config' do
140
+ date = Date.today
141
+ cell_class = @calendar.send(:day_cell_classes, date)
142
+ expect(cell_class).to eq('rspec-test-cell rspec-today')
143
+ end
144
+ end
145
+
146
+ context 'if the date is from another month' do
147
+ it 'should have the class specified by another_month config' do
148
+ date = Date.today
149
+ cell_class = @calendar.send(:day_cell_classes, date)
150
+ expect(cell_class).to eq('rspec-test-cell rspec-today')
151
+ end
152
+ end
153
+ end
154
+
155
+ describe '#date_callback(date)' do
156
+ context 'if the calendar has a callback' do
157
+ before do
158
+ @calendar.callback = Proc.new do |date|
159
+ date == Date.today ? 'today' : 'not today'
160
+ end
161
+ end
162
+
163
+ context 'if the calendar has a view context' do
164
+ before do
165
+ @view_context = double('view_context')
166
+ @calendar.view_context = @view_context
167
+ end
168
+
169
+ it 'should capture the block with the view context' do
170
+ expect(@view_context).to receive(:capture)
171
+ @calendar.send(:date_callback, Date.today)
172
+ end
173
+ end
174
+
175
+ context 'if the calendar noes not have a view context' do
176
+ before do
177
+ @calendar.view_context = nil
178
+ end
179
+
180
+ it 'should capture the block with the default context' do
181
+ expect(@calendar).to receive(:capture)
182
+ @calendar.send(:date_callback, Date.today)
183
+ end
184
+ end
185
+
186
+ it 'should return the callback output' do
187
+ output = @calendar.send(:date_callback, Date.today)
188
+ expect(output).to eq('today')
189
+
190
+ output = @calendar.send(:date_callback, 1.day.ago)
191
+ expect(output).to eq('not today')
192
+ end
193
+ end
194
+
195
+ context 'if the calendar does not have a callback' do
196
+ before do
197
+ @calendar.callback = nil
198
+ end
199
+
200
+ it 'should return nothing' do
201
+ expect(@calendar.send(:date_callback, Date.today)).to_not be_present
202
+ end
203
+ end
204
+ end
205
+
206
+ describe '#day_cell(date)' do
207
+ before do
208
+ @date = Date.strptime('1900-01-20')
209
+ end
210
+
211
+ it 'should render a td tag' do
212
+ cell = @calendar.send(:day_cell, @date)
213
+ expect(cell).to have_selector('td')
214
+ end
215
+
216
+ it 'should render a span with the day number' do
217
+ cell = @calendar.send(:day_cell, @date)
218
+ expect(cell).to have_selector('td > span', text: '20')
219
+ end
220
+
221
+ it 'should invoke date_callback passing the current date' do
222
+ expect(@calendar).to receive(:date_callback).with(@date)
223
+ @calendar.send(:day_cell, @date)
224
+ end
225
+
226
+ context 'if date_callback returns something' do
227
+ it 'should render a div with the output' do
228
+ allow(@calendar).to receive(:date_callback).and_return('test output')
229
+ cell = @calendar.send(:day_cell, @date)
230
+ expect(cell).to have_selector('td > div', text: 'test output')
231
+ end
232
+
233
+ context 'the div' do
234
+ it 'should have the class specified by day_contents_class config' do
235
+ RailsCalendar.configuration.class_prefix = 'rspec-'
236
+ RailsCalendar.configuration.day_contents_class = 'test-day'
237
+
238
+ allow(@calendar).to receive(:date_callback).and_return('test output')
239
+ cell = @calendar.send(:day_cell, @date)
240
+ expect(cell).to have_selector('td > div.rspec-test-day')
241
+ end
242
+ end
243
+ end
244
+
245
+ context 'if date_callback returns nothing' do
246
+ it 'should not render a div' do
247
+ allow(@calendar).to receive(:date_callback)
248
+ cell = @calendar.send(:day_cell, @date)
249
+ expect(cell).to_not have_selector('td > div')
250
+ end
251
+ end
252
+
253
+ context 'the td' do
254
+ it 'should assign de class returned by day_cell_classes' do
255
+ allow(@calendar).to receive(:day_cell_classes).and_return('test-class')
256
+ cell = @calendar.send(:day_cell, @date)
257
+ expect(cell).to have_selector('td.test-class')
258
+ end
259
+ end
260
+
261
+ context 'the day number span' do
262
+ it 'should have the class specified by day_number_class config' do
263
+ RailsCalendar.configuration.class_prefix = 'rspec-'
264
+ RailsCalendar.configuration.day_number_class = 'test-day'
265
+
266
+ cell = @calendar.send(:day_cell, @date)
267
+ expect(cell).to have_selector('td > span.rspec-test-day')
268
+ end
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,23 @@
1
+ describe RailsCalendar do
2
+ describe '.configuration' do
3
+ it 'should be an instance of RailsCalendar::Configuration' do
4
+ expect(RailsCalendar.configuration).to be_a(RailsCalendar::Configuration)
5
+ end
6
+ end
7
+
8
+ describe '.configure' do
9
+ it 'should expose the configuration in a block' do
10
+ RailsCalendar.configure do |config|
11
+ expect(config).to be(RailsCalendar.configuration)
12
+ end
13
+ end
14
+
15
+ it 'should override any writen configuration' do
16
+ RailsCalendar.configure do |config|
17
+ config.i18n_days = 'i18n_test'
18
+ end
19
+
20
+ expect(RailsCalendar.configuration.i18n_days).to eq('i18n_test')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,84 @@
1
+ require 'capybara/rspec'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'rails_calendar'
6
+
7
+ # This file was generated by the `rspec --init` command. Conventionally, all
8
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
9
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
10
+ # file to always be loaded, without a need to explicitly require it in any files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, make a
16
+ # separate helper file that requires this one and then use it only in the specs
17
+ # that actually need it.
18
+ #
19
+ # The `.rspec` file also contains a few flags that are not defaults but that
20
+ # users commonly want.
21
+ #
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
+ RSpec.configure do |config|
24
+ # The settings below are suggested to provide a good initial experience
25
+ # with RSpec, but feel free to customize to your heart's content.
26
+ =begin
27
+ # These two settings work together to allow you to limit a spec run
28
+ # to individual examples or groups you care about by tagging them with
29
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
30
+ # get run.
31
+ config.filter_run :focus
32
+ config.run_all_when_everything_filtered = true
33
+
34
+ # Many RSpec users commonly either run the entire suite or an individual
35
+ # file, and it's useful to allow more verbose output when running an
36
+ # individual spec file.
37
+ if config.files_to_run.one?
38
+ # Use the documentation formatter for detailed output,
39
+ # unless a formatter has already been configured
40
+ # (e.g. via a command-line flag).
41
+ config.default_formatter = 'doc'
42
+ end
43
+
44
+ # Print the 10 slowest examples and example groups at the
45
+ # end of the spec run, to help surface which specs are running
46
+ # particularly slow.
47
+ config.profile_examples = 10
48
+
49
+ # Run specs in random order to surface order dependencies. If you find an
50
+ # order dependency and want to debug it, you can fix the order by providing
51
+ # the seed, which is printed after each run.
52
+ # --seed 1234
53
+ config.order = :random
54
+
55
+ # Seed global randomization in this process using the `--seed` CLI option.
56
+ # Setting this allows you to use `--seed` to deterministically reproduce
57
+ # test failures related to randomization by passing the same `--seed` value
58
+ # as the one that triggered the failure.
59
+ Kernel.srand config.seed
60
+
61
+ # rspec-expectations config goes here. You can use an alternate
62
+ # assertion/expectation library such as wrong or the stdlib/minitest
63
+ # assertions if you prefer.
64
+ config.expect_with :rspec do |expectations|
65
+ # Enable only the newer, non-monkey-patching expect syntax.
66
+ # For more details, see:
67
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
68
+ expectations.syntax = :expect
69
+ end
70
+
71
+ # rspec-mocks config goes here. You can use an alternate test double
72
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
73
+ config.mock_with :rspec do |mocks|
74
+ # Enable only the newer, non-monkey-patching expect syntax.
75
+ # For more details, see:
76
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
77
+ mocks.syntax = :expect
78
+
79
+ # Prevents you from mocking or stubbing a method that does not exist on
80
+ # a real object. This is generally recommended.
81
+ mocks.verify_partial_doubles = true
82
+ end
83
+ =end
84
+ end
@@ -0,0 +1,18 @@
1
+ .calendar-table
2
+ border-collapse: collapse
3
+ box-sizing: border-box
4
+
5
+ .calendar-day-cell, .calendar-day-name
6
+ border: #000 solid 1px
7
+ width: 14.28571428571429%
8
+
9
+ .calendar-day-cell
10
+ padding: 4px
11
+ vertical-align: top
12
+
13
+ .calendar-day-name
14
+ padding: 4px 10px
15
+
16
+ .calendar-day-number
17
+ display: block
18
+ text-align: right
@@ -0,0 +1,25 @@
1
+ .calendar-table
2
+ background: #fff
3
+ font-family: Helvetica
4
+
5
+ .calendar-day-cell
6
+ border: #ddd solid 1px
7
+ height: 30px
8
+
9
+ .calendar-day-name
10
+ border: none
11
+ font-size: 1.1em
12
+
13
+ .calendar-day-number
14
+ color: #666
15
+ font-size: .8em
16
+
17
+ .calendar-day-contents
18
+ font-size: .9em
19
+
20
+ .calendar-today
21
+ .calendar-day-number
22
+ color: #d00
23
+
24
+ .calendar-another-month
25
+ opacity: .5
@@ -0,0 +1,3 @@
1
+ //= require rails_calendar/base
2
+ //= require rails_calendar/theme
3
+ //= require_self