simple_calendar 2.4.1 → 2.4.2
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +43 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/README.md +56 -15
- data/Rakefile +1 -1
- data/app/views/simple_calendar/_week_calendar.html.erb +5 -5
- data/gemfiles/rails_6.gemfile +9 -0
- data/gemfiles/rails_6.gemfile.lock +197 -0
- data/gemfiles/rails_6_1.gemfile +9 -0
- data/gemfiles/rails_6_1.gemfile.lock +200 -0
- data/gemfiles/rails_master.gemfile +9 -0
- data/gemfiles/rails_master.gemfile.lock +205 -0
- data/lib/generators/simple_calendar/views_generator.rb +2 -2
- data/lib/simple_calendar/calendar.rb +54 -54
- data/lib/simple_calendar/month_calendar.rb +0 -1
- data/lib/simple_calendar/version.rb +1 -1
- data/lib/simple_calendar/view_helpers.rb +6 -6
- data/lib/simple_calendar/week_calendar.rb +1 -1
- data/simple_calendar.gemspec +12 -13
- data/spec/calendar_spec.rb +39 -39
- data/spec/calendars/month_calendar_spec.rb +8 -8
- data/spec/simple_calendar_spec.rb +4 -4
- data/spec/spec_helper.rb +53 -53
- data/spec/support/fake_event.rb +3 -3
- data/spec/support/view_context.rb +1 -1
- data/spec/views_generators_spec.rb +3 -3
- metadata +12 -4
- data/.travis.yml +0 -5
@@ -1,17 +1,17 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
module ViewHelpers
|
3
|
-
def calendar(options={}, &block)
|
4
|
-
raise
|
3
|
+
def calendar(options = {}, &block)
|
4
|
+
raise "calendar requires a block" unless block
|
5
5
|
SimpleCalendar::Calendar.new(self, options).render(&block)
|
6
6
|
end
|
7
7
|
|
8
|
-
def month_calendar(options={}, &block)
|
9
|
-
raise
|
8
|
+
def month_calendar(options = {}, &block)
|
9
|
+
raise "month_calendar requires a block" unless block
|
10
10
|
SimpleCalendar::MonthCalendar.new(self, options).render(&block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def week_calendar(options={}, &block)
|
14
|
-
raise
|
13
|
+
def week_calendar(options = {}, &block)
|
14
|
+
raise "week_calendar requires a block" unless block
|
15
15
|
SimpleCalendar::WeekCalendar.new(self, options).render(&block)
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleCalendar
|
2
2
|
class WeekCalendar < SimpleCalendar::Calendar
|
3
3
|
def week_number
|
4
|
-
format =
|
4
|
+
format = Date.beginning_of_week == :sunday ? "%U" : "%V"
|
5
5
|
start_date.beginning_of_week.strftime(format).to_i
|
6
6
|
end
|
7
7
|
|
data/simple_calendar.gemspec
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
$:.push File.expand_path("../lib", __FILE__)
|
3
2
|
require "simple_calendar/version"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
|
-
s.name
|
7
|
-
s.version
|
8
|
-
s.authors
|
9
|
-
s.email
|
10
|
-
s.homepage
|
11
|
-
s.summary
|
12
|
-
s.description =
|
13
|
-
s.license
|
5
|
+
s.name = "simple_calendar"
|
6
|
+
s.version = SimpleCalendar::VERSION
|
7
|
+
s.authors = ["Chris Oliver"]
|
8
|
+
s.email = ["excid3@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/excid3/simple_calendar"
|
10
|
+
s.summary = "A simple Rails calendar"
|
11
|
+
s.description = "A simple Rails calendar"
|
12
|
+
s.license = "MIT"
|
14
13
|
|
15
14
|
s.rubyforge_project = "simple_calendar"
|
16
15
|
|
17
|
-
s.files
|
18
|
-
s.test_files
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
18
|
s.require_paths = ["lib"]
|
20
19
|
|
21
|
-
s.add_dependency
|
22
|
-
s.add_development_dependency
|
20
|
+
s.add_dependency "rails", ">= 3.0"
|
21
|
+
s.add_development_dependency "rspec"
|
23
22
|
end
|
data/spec/calendar_spec.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require_relative
|
5
|
-
require_relative
|
1
|
+
require "spec_helper"
|
2
|
+
require "action_controller"
|
3
|
+
require "simple_calendar/calendar"
|
4
|
+
require_relative "support/fake_event"
|
5
|
+
require_relative "support/view_context"
|
6
6
|
|
7
7
|
describe SimpleCalendar::Calendar do
|
8
8
|
let(:calendar) { SimpleCalendar::Calendar.new(ViewContext.new) }
|
9
9
|
|
10
|
-
it
|
10
|
+
it "renders a partial with the same name as the class" do
|
11
11
|
expect(calendar.send(:partial_name)).to eq("simple_calendar/calendar")
|
12
12
|
end
|
13
13
|
|
14
|
-
context
|
15
|
-
it
|
14
|
+
context "event sorting attribute" do
|
15
|
+
it "has start_time as the default attribute" do
|
16
16
|
expect(calendar.send(:attribute)).to eq(:start_time)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it "allows you to override the default attribute" do
|
20
20
|
expect(SimpleCalendar::Calendar.new(ViewContext.new, attribute: :starts_at).send(:attribute)).to eq(:starts_at)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "set a default when `partial` option isn't present" do
|
24
|
-
expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq(
|
25
|
-
expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq(
|
26
|
-
expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq(
|
24
|
+
expect(SimpleCalendar::Calendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/calendar")
|
25
|
+
expect(SimpleCalendar::MonthCalendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/month_calendar")
|
26
|
+
expect(SimpleCalendar::WeekCalendar.new(ViewContext.new).send(:partial_name)).to eq("simple_calendar/week_calendar")
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
expect(SimpleCalendar::Calendar.new(ViewContext.new, partial:
|
29
|
+
it "allows to override the default partial" do
|
30
|
+
expect(SimpleCalendar::Calendar.new(ViewContext.new, partial: "simple_calendar/custom_calendar").send(:partial_name)).to eq("simple_calendar/custom_calendar")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
describe "#sorted_events" do
|
35
|
-
it
|
35
|
+
it "converts an array of events to a hash sorted by days" do
|
36
36
|
today, tomorrow = Date.today, Date.tomorrow
|
37
37
|
|
38
38
|
event1 = double(start_time: today.at_midnight)
|
@@ -48,7 +48,7 @@ describe SimpleCalendar::Calendar do
|
|
48
48
|
expect(sorted_events[tomorrow]).to eq([event3])
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it "converts an array of multi-day events to a hash sorted by days" do
|
52
52
|
today, tomorrow = Date.today, Date.tomorrow
|
53
53
|
|
54
54
|
event1 = double(start_time: today.at_midnight, end_time: tomorrow.at_midnight)
|
@@ -64,17 +64,17 @@ describe SimpleCalendar::Calendar do
|
|
64
64
|
expect(sorted_events[tomorrow]).to eq([event1, event3])
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it "handles events without a start time" do
|
68
68
|
event = double(start_time: nil)
|
69
69
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: [event])
|
70
70
|
|
71
|
-
expect{calendar.send(:sorted_events)}.not_to raise_error
|
71
|
+
expect { calendar.send(:sorted_events) }.not_to raise_error
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe "#start_date" do
|
76
76
|
it "defaults to today's date" do
|
77
|
-
view_context = ViewContext.new
|
77
|
+
view_context = ViewContext.new
|
78
78
|
calendar = SimpleCalendar::Calendar.new(view_context)
|
79
79
|
expect(calendar.send(:start_date)).to eq(Date.today)
|
80
80
|
end
|
@@ -98,21 +98,21 @@ describe SimpleCalendar::Calendar do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe
|
102
|
-
it
|
101
|
+
describe "current week class" do
|
102
|
+
it "should have the current week" do
|
103
103
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
104
104
|
week = calendar.date_range.each_slice(7).to_a[0]
|
105
|
-
expect(calendar.send(:tr_classes_for, week)).to include(
|
105
|
+
expect(calendar.send(:tr_classes_for, week)).to include("current-week")
|
106
106
|
end
|
107
107
|
|
108
|
-
it
|
108
|
+
it "should not have the current week if it does not contain today" do
|
109
109
|
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new(6.months.ago))
|
110
110
|
week = calendar.date_range.each_slice(7).to_a[0]
|
111
|
-
expect(calendar.send(:tr_classes_for, week)).to_not include(
|
111
|
+
expect(calendar.send(:tr_classes_for, week)).to_not include("current-week")
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it "has a param that determines the start date of the calendar" do
|
116
116
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
117
117
|
|
118
118
|
rendering_variables = calendar.render[:locals]
|
@@ -120,7 +120,7 @@ describe SimpleCalendar::Calendar do
|
|
120
120
|
expect(rendering_variables[:start_date]).not_to be_nil
|
121
121
|
end
|
122
122
|
|
123
|
-
it
|
123
|
+
it "generates a default date if no start date is present" do
|
124
124
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
125
125
|
|
126
126
|
calendar_start_date = calendar.render[:locals][:start_date]
|
@@ -129,7 +129,7 @@ describe SimpleCalendar::Calendar do
|
|
129
129
|
expect(calendar_start_date).to be_a(Date)
|
130
130
|
end
|
131
131
|
|
132
|
-
it
|
132
|
+
it "has a range of dates" do
|
133
133
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new)
|
134
134
|
|
135
135
|
calendar_date_range = calendar.date_range
|
@@ -138,14 +138,14 @@ describe SimpleCalendar::Calendar do
|
|
138
138
|
expect(calendar_date_range).to all(be_an(Date))
|
139
139
|
end
|
140
140
|
|
141
|
-
it
|
142
|
-
it
|
143
|
-
it
|
144
|
-
it
|
141
|
+
it "can split the range of dates into weeks"
|
142
|
+
it "has a title"
|
143
|
+
it "has a next view link"
|
144
|
+
it "has a previous view link"
|
145
145
|
|
146
|
-
it
|
147
|
-
first_event = FakeEvent.new(
|
148
|
-
second_event = FakeEvent.new(
|
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
149
|
events = [first_event, second_event]
|
150
150
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
151
151
|
|
@@ -154,10 +154,10 @@ describe SimpleCalendar::Calendar do
|
|
154
154
|
expect(calendar_sorted_events.length).to eq(2)
|
155
155
|
end
|
156
156
|
|
157
|
-
it
|
158
|
-
first_event = FakeEvent.new(
|
159
|
-
second_event = FakeEvent.new(
|
160
|
-
third_event = FakeEvent.new(
|
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
161
|
events = [first_event, third_event, second_event]
|
162
162
|
calendar = SimpleCalendar::Calendar.new(ViewContext.new, events: events)
|
163
163
|
|
@@ -171,6 +171,6 @@ describe SimpleCalendar::Calendar do
|
|
171
171
|
expect(calendar_sorted_events[third_key][0]).to eq(first_event)
|
172
172
|
end
|
173
173
|
|
174
|
-
it
|
174
|
+
it "yields the events for each day"
|
175
175
|
it "doesn't crash when an event has a nil start_time"
|
176
176
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "action_controller"
|
3
|
+
require "simple_calendar/calendar"
|
4
|
+
require "simple_calendar/month_calendar"
|
5
|
+
require "support/view_context"
|
6
6
|
|
7
7
|
describe SimpleCalendar::MonthCalendar do
|
8
|
-
describe
|
9
|
-
it
|
8
|
+
describe "#date_range" do
|
9
|
+
it "renders a full calendar month" do
|
10
10
|
today = Date.today
|
11
11
|
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: Date.today)
|
12
12
|
|
@@ -14,7 +14,7 @@ describe SimpleCalendar::MonthCalendar do
|
|
14
14
|
expect(calendar.date_range.max).to be >= today.end_of_month
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
17
|
+
it "render the days of next and previous months on the edges of the calendar" do
|
18
18
|
month = Date.new(2018, 8, 1)
|
19
19
|
calendar = SimpleCalendar::MonthCalendar.new(ViewContext.new, start_date: month)
|
20
20
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "rails"
|
3
|
+
require "simple_calendar"
|
4
4
|
|
5
5
|
describe SimpleCalendar do
|
6
|
-
it
|
6
|
+
it "has a version number" do
|
7
7
|
expect(SimpleCalendar::VERSION).not_to be nil
|
8
8
|
end
|
9
9
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "active_support/all"
|
2
|
+
|
1
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
5
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
@@ -40,57 +42,55 @@ RSpec.configure do |config|
|
|
40
42
|
mocks.verify_partial_doubles = true
|
41
43
|
end
|
42
44
|
|
43
|
-
# The settings below are suggested to provide a good initial experience
|
44
|
-
# with RSpec, but feel free to customize to your heart's content.
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
config.
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
#
|
60
|
-
# - http://
|
61
|
-
# - http://
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
|
83
|
-
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
Kernel.srand config.seed
|
95
|
-
=end
|
45
|
+
# The settings below are suggested to provide a good initial experience
|
46
|
+
# with RSpec, but feel free to customize to your heart's content.
|
47
|
+
# # These two settings work together to allow you to limit a spec run
|
48
|
+
# # to individual examples or groups you care about by tagging them with
|
49
|
+
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
50
|
+
# # get run.
|
51
|
+
# config.filter_run :focus
|
52
|
+
# config.run_all_when_everything_filtered = true
|
53
|
+
#
|
54
|
+
# # Allows RSpec to persist some state between runs in order to support
|
55
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
56
|
+
# # you configure your source control system to ignore this file.
|
57
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
58
|
+
#
|
59
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
60
|
+
# # recommended. For more details, see:
|
61
|
+
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
63
|
+
# # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
64
|
+
# config.disable_monkey_patching!
|
65
|
+
#
|
66
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
67
|
+
# # be too noisy due to issues in dependencies.
|
68
|
+
# config.warnings = true
|
69
|
+
#
|
70
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
71
|
+
# # file, and it's useful to allow more verbose output when running an
|
72
|
+
# # individual spec file.
|
73
|
+
# if config.files_to_run.one?
|
74
|
+
# # Use the documentation formatter for detailed output,
|
75
|
+
# # unless a formatter has already been configured
|
76
|
+
# # (e.g. via a command-line flag).
|
77
|
+
# config.default_formatter = 'doc'
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# # Print the 10 slowest examples and example groups at the
|
81
|
+
# # end of the spec run, to help surface which specs are running
|
82
|
+
# # particularly slow.
|
83
|
+
# config.profile_examples = 10
|
84
|
+
#
|
85
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
86
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
87
|
+
# # the seed, which is printed after each run.
|
88
|
+
# # --seed 1234
|
89
|
+
# config.order = :random
|
90
|
+
#
|
91
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
92
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
93
|
+
# # test failures related to randomization by passing the same `--seed` value
|
94
|
+
# # as the one that triggered the failure.
|
95
|
+
# Kernel.srand config.seed
|
96
96
|
end
|
data/spec/support/fake_event.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class FakeEvent
|
2
2
|
attr_accessor :name, :start_time, :end_time
|
3
3
|
|
4
|
-
def initialize(name=
|
5
|
-
@name
|
4
|
+
def initialize(name = "event", start_time = nil, end_time = nil)
|
5
|
+
@name = name
|
6
6
|
@start_time = start_time
|
7
|
-
@end_time
|
7
|
+
@end_time = end_time
|
8
8
|
end
|
9
9
|
end
|
@@ -2,6 +2,6 @@ require "spec_helper"
|
|
2
2
|
require "generators/simple_calendar/views_generator"
|
3
3
|
|
4
4
|
describe SimpleCalendar::Generators::ViewsGenerator do
|
5
|
-
|
6
|
-
|
7
|
-
end
|
5
|
+
it "copies the files to app/views/simple_calendar"
|
6
|
+
it "verifies the content"
|
7
|
+
end
|