simple_calendar 2.2.7 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7f4f3e0cb295f0632eee3bac373fecfabfa70643
4
- data.tar.gz: 013c371f81fe1487985b52dd3f33d9eadafa493f
2
+ SHA256:
3
+ metadata.gz: 498acc5a1c5fac24d47d7cdb9d3da21744bfa262d593dd2c1ea38fd15285d35e
4
+ data.tar.gz: '0689bdad34c54a9e5aad30c200d22cc3502326431db2a4525eb944e15d6436ba'
5
5
  SHA512:
6
- metadata.gz: 98ffbd3a7116c88b0e4d3d474f473c338378e8e7b4567f0a7c0bc2bd4dc9fc34479b68035c6b0f8234f956df911b8e8b52ff68cb425531562a61cad07c7698b9
7
- data.tar.gz: 2a9ee6d963304596ae166bf2413a7bc352a81f0bccd65ba05599119f5ff2726842a3b1bf59104a9670f8270eb2f425473c2a3efd2a4f421783c9945f63aeae28
6
+ metadata.gz: 65ad74303562bb5f3126732963dd8776871463234ef3ae3c53a309e0462d24d393e5cc40ad9ec2eee57996d7456f2c9440237753e4fad13c5b98d49da4799539
7
+ data.tar.gz: a46c0c61bacb99afd4e3265a0eaf165c408fda9b005954221732408e7250124d60e9dd04649a3705893df89cbe5aee1077f58324c02f742c242c36fd1d20447a
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- - 2.2.5
3
+ - 2.4.2
4
+ - 2.3.5
5
+ - 2.2.8
data/README.md CHANGED
@@ -24,6 +24,16 @@ Just add this into your Gemfile followed by a bundle install:
24
24
  gem "simple_calendar", "~> 2.0"
25
25
  ```
26
26
 
27
+ If you're using Bootstrap, the calendar should already have a border and
28
+ nice spacing for days.
29
+
30
+ Optionally, you can include the default stylesheet for the calendar in
31
+ your `app/assets/stylesheets/application.css` file:
32
+
33
+ ```scss
34
+ *= require simple_calendar
35
+ ```
36
+
27
37
  Usage
28
38
  -----
29
39
 
@@ -92,8 +102,6 @@ You can set a different partial name for calendars by passing the partial path.
92
102
  <% end %>
93
103
  ```
94
104
 
95
- Setting `number_of_days` is optional and defaults to 4.
96
-
97
105
  ## Rendering Events
98
106
 
99
107
  What's a calendar without events in it? There are two simple steps for creating
@@ -197,7 +205,7 @@ edit to your heart's desire.
197
205
  Setting `Time.zone` will make sure the calendar start days are correctly computed
198
206
  in the right timezone. You can set this globally in your `application.rb` file or
199
207
  if you have a User model with a time_zone attribute, you can set it on every request by using
200
- a before_filter like the following example.
208
+ a before_action like the following example.
201
209
 
202
210
  This code example uses [Devise](https://github.com/plataformatec/devise)'s
203
211
  `current_user` and `user_signed_in?` methods to retrieve the user's timezone and set it for the duration of the request.
@@ -206,7 +214,7 @@ using some other method of authentication.
206
214
 
207
215
  ```ruby
208
216
  class ApplicationController < ActionController::Base
209
- before_filter :set_time_zone, if: :user_signed_in?
217
+ before_action :set_time_zone, if: :user_signed_in?
210
218
 
211
219
  private
212
220
 
@@ -226,7 +234,7 @@ config.time_zone = 'Central Time (US & Canada)'
226
234
  ### Beginning Of Week
227
235
 
228
236
  You can also change the beginning day of the week by setting
229
- `Date.beginning_of_week` in a `before_filter` just like in the previous
237
+ `Date.beginning_of_week` in a `before_action` just like in the previous
230
238
  example. If you want to set this globally, you can put this line in
231
239
  `config/application.rb`:
232
240
 
@@ -234,18 +242,6 @@ example. If you want to set this globally, you can put this line in
234
242
  config.beginning_of_week = :sunday
235
243
  ```
236
244
 
237
- ### Default Stylesheet
238
-
239
- If you're using Bootstrap, the calendar should already have a border and
240
- nice spacing for days.
241
-
242
- Optionally, you can include the default stylesheet for the calendar in
243
- your `app/assets/stylesheets/application.css` file:
244
-
245
- ```scss
246
- *= require simple_calendar
247
- ```
248
-
249
245
  ### Custom CSS Classes
250
246
 
251
247
  Setting classes on the table and elements are pretty easy.
@@ -65,6 +65,10 @@ module SimpleCalendar
65
65
  view_context.url_for(@params.merge(start_date_param => date_range.first - 1.day))
66
66
  end
67
67
 
68
+ def date_range
69
+ (start_date..(start_date + additional_days.days)).to_a
70
+ end
71
+
68
72
  private
69
73
 
70
74
  def partial_name
@@ -116,10 +120,6 @@ module SimpleCalendar
116
120
  date_range.last
117
121
  end
118
122
 
119
- def date_range
120
- (start_date..(start_date + additional_days.days)).to_a
121
- end
122
-
123
123
  def additional_days
124
124
  options.fetch(:number_of_days, 4) - 1
125
125
  end
@@ -1,10 +1,8 @@
1
1
  module SimpleCalendar
2
2
  class MonthCalendar < SimpleCalendar::Calendar
3
- private
4
-
5
- def date_range
6
- (start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
7
- end
3
+ def date_range
4
+ (start_date.beginning_of_month.beginning_of_week..start_date.end_of_month.end_of_week).to_a
5
+ end
8
6
  end
9
7
  end
10
8
 
@@ -1,3 +1,3 @@
1
1
  module SimpleCalendar
2
- VERSION = "2.2.7"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -13,13 +13,11 @@ module SimpleCalendar
13
13
  week_number + number_of_weeks - 1
14
14
  end
15
15
 
16
- private
16
+ def date_range
17
+ starting = start_date.beginning_of_week
18
+ ending = (starting + (number_of_weeks - 1).weeks).end_of_week
17
19
 
18
- def date_range
19
- starting = start_date.beginning_of_week
20
- ending = (starting + (number_of_weeks - 1).weeks).end_of_week
21
-
22
- (starting..ending).to_a
23
- end
20
+ (starting..ending).to_a
21
+ end
24
22
  end
25
23
  end
@@ -1,23 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'action_controller'
3
3
  require 'simple_calendar/calendar'
4
-
5
- class ViewContext
6
- attr_accessor :start_date, :start_date_param
7
-
8
- def initialize(start_date=nil, options={})
9
- @start_date = start_date
10
- @start_date_param = options.fetch(:start_date_param, :start_date)
11
- end
12
-
13
- def params
14
- if @start_date.present?
15
- ActionController::Parameters.new({start_date_param => @start_date})
16
- else
17
- ActionController::Parameters.new
18
- end
19
- end
20
- end
4
+ require_relative 'support/fake_event'
5
+ require_relative 'support/view_context'
21
6
 
22
7
  describe SimpleCalendar::Calendar do
23
8
  let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
@@ -116,29 +101,76 @@ describe SimpleCalendar::Calendar do
116
101
  describe 'current week class' do
117
102
  it 'should have the current week' do
118
103
  calendar = SimpleCalendar::Calendar.new(ViewContext.new)
119
- week = calendar.send(:date_range).each_slice(7).to_a[0]
104
+ week = calendar.date_range.each_slice(7).to_a[0]
120
105
  expect(calendar.send(:tr_classes_for, week)).to include('current-week')
121
106
  end
122
107
 
123
108
  it 'should not have the current week if it does not contain today' do
124
- calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new)
125
- week = calendar.send(:date_range).each_slice(7).to_a[0]
109
+ calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new(6.months.ago))
110
+ week = calendar.date_range.each_slice(7).to_a[0]
126
111
  expect(calendar.send(:tr_classes_for, week)).to_not include('current-week')
127
112
  end
128
113
  end
129
114
 
130
- it 'has a param that determines the start date of the calendar'
131
- it 'generates a default date if no start date is present'
132
- it 'has a range of dates'
115
+ it 'has a param that determines the start date of the calendar' do
116
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new)
117
+
118
+ rendering_variables = calendar.render[:locals]
119
+
120
+ expect(rendering_variables[:start_date]).not_to be_nil
121
+ end
122
+
123
+ it 'generates a default date if no start date is present' do
124
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new)
125
+
126
+ calendar_start_date = calendar.render[:locals][:start_date]
127
+
128
+ expect(calendar_start_date).not_to be_nil
129
+ expect(calendar_start_date).to be_a(Date)
130
+ end
131
+
132
+ it 'has a range of dates' do
133
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new)
134
+
135
+ calendar_date_range = calendar.date_range
136
+
137
+ expect(calendar_date_range).to be_an(Array)
138
+ expect(calendar_date_range).to all(be_an(Date))
139
+ end
133
140
 
134
141
  it 'can split the range of dates into weeks'
135
142
  it 'has a title'
136
143
  it 'has a next view link'
137
144
  it 'has a previous view link'
138
145
 
139
- it 'accepts an array of events'
140
- it 'sorts the events'
141
- it 'yields the events for each day'
146
+ it 'accepts an array of events' do
147
+ first_event = FakeEvent.new('event1', Date.today)
148
+ second_event = FakeEvent.new('event2', Date.today + 1.day)
149
+ events = [first_event, second_event]
150
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
142
151
 
152
+ calendar_sorted_events = calendar.render[:locals][:sorted_events]
153
+
154
+ expect(calendar_sorted_events.length).to eq(2)
155
+ end
156
+
157
+ it 'sorts the events' do
158
+ first_event = FakeEvent.new('event1', Date.today + 2.days)
159
+ second_event = FakeEvent.new('event2', Date.today + 1.day)
160
+ third_event = FakeEvent.new('event3', Date.today)
161
+ events = [first_event, third_event, second_event]
162
+ calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
163
+
164
+ calendar_sorted_events = calendar.render[:locals][:sorted_events]
165
+ first_key = calendar_sorted_events.keys[0]
166
+ second_key = calendar_sorted_events.keys[1]
167
+ third_key = calendar_sorted_events.keys[2]
168
+
169
+ expect(calendar_sorted_events[first_key][0]).to eq(third_event)
170
+ expect(calendar_sorted_events[second_key][0]).to eq(second_event)
171
+ expect(calendar_sorted_events[third_key][0]).to eq(first_event)
172
+ end
173
+
174
+ it 'yields the events for each day'
143
175
  it "doesn't crash when an event has a nil start_time"
144
176
  end
@@ -1,7 +1,25 @@
1
1
  require 'spec_helper'
2
+ require 'action_controller'
3
+ require 'simple_calendar/calendar'
2
4
  require 'simple_calendar/month_calendar'
5
+ require 'support/view_context'
3
6
 
4
7
  describe SimpleCalendar::MonthCalendar do
5
- it 'renders a full calendar month'
6
- it 'render the days of next and previous months on the edges of the calendar'
8
+ describe '#date_range' do
9
+ it 'renders a full calendar month' do
10
+ today = Date.today
11
+ calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: Date.today)
12
+
13
+ expect(calendar.date_range.min).to be < today.beginning_of_month
14
+ expect(calendar.date_range.max).to be > today.end_of_month
15
+ end
16
+
17
+ it 'render the days of next and previous months on the edges of the calendar' do
18
+ month = Date.new(2018, 8, 1)
19
+ calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: month)
20
+
21
+ expect(calendar.date_range.first).to eq Date.new(2018, 7, 30)
22
+ expect(calendar.date_range.last).to eq Date.new(2018, 9, 2)
23
+ end
24
+ end
7
25
  end
@@ -0,0 +1,9 @@
1
+ class FakeEvent
2
+ attr_accessor :name, :start_time, :end_time
3
+
4
+ def initialize(name='event', start_time=nil, end_time=nil)
5
+ @name = name
6
+ @start_time = start_time
7
+ @end_time = end_time
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ class ViewContext
2
+ attr_accessor :start_date, :start_date_param
3
+
4
+ def initialize(start_date=nil, options={})
5
+ @start_date = start_date
6
+ @start_date_param = options.fetch(:start_date_param, :start_date)
7
+ end
8
+
9
+ def params
10
+ if @start_date.present?
11
+ ActionController::Parameters.new({start_date_param => @start_date})
12
+ else
13
+ ActionController::Parameters.new
14
+ end
15
+ end
16
+
17
+ def render(options = {})
18
+ options
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.7
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Oliver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -71,6 +71,8 @@ files:
71
71
  - spec/calendars/month_calendar_spec.rb
72
72
  - spec/simple_calendar_spec.rb
73
73
  - spec/spec_helper.rb
74
+ - spec/support/fake_event.rb
75
+ - spec/support/view_context.rb
74
76
  - spec/views_generators_spec.rb
75
77
  homepage: https://github.com/excid3/simple_calendar
76
78
  licenses:
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  requirements: []
94
96
  rubyforge_project: simple_calendar
95
- rubygems_version: 2.6.11
97
+ rubygems_version: 2.7.6
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: A simple Rails calendar
@@ -101,4 +103,6 @@ test_files:
101
103
  - spec/calendars/month_calendar_spec.rb
102
104
  - spec/simple_calendar_spec.rb
103
105
  - spec/spec_helper.rb
106
+ - spec/support/fake_event.rb
107
+ - spec/support/view_context.rb
104
108
  - spec/views_generators_spec.rb