gb_work_day 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'gb_work_day/helpers/date'
3
+ require 'gb_work_day/core_ext/date'
4
+ require 'active_support/time'
5
+
6
+ describe GBWorkDay::Date do
7
+
8
+ it 'should be a subclass of date' do
9
+ expect(GBWorkDay::Date.today).to be_kind_of ::Date
10
+ end
11
+
12
+ it 'should be able to make a copy form other date instance' do
13
+ old_date = ::Date.today
14
+ expect(GBWorkDay::Date.from_date old_date).to be_kind_of GBWorkDay::Date
15
+ expect(GBWorkDay::Date.from_date old_date).to eq old_date
16
+ end
17
+
18
+ it 'should return work day duration on subtraction' do
19
+ monday = Date.today.beginning_of_week
20
+ wednesday = monday + 2.days
21
+ expect(GBWorkDay::Date.from_date(wednesday) - monday).to be_kind_of GBWorkDay::Duration
22
+ expect(GBWorkDay::Date.from_date(wednesday) - GBWorkDay::Date.from_date(monday)).to be_kind_of GBWorkDay::Duration
23
+ expect(GBWorkDay::Date.from_date(monday) - 1).to be_kind_of Date
24
+ expect((wednesday - GBWorkDay::Date.from_date(monday))).to be_kind_of GBWorkDay::Duration
25
+ end
26
+
27
+ it 'should use set week for work? method' do
28
+ week = GBWorkDay::WorkWeek.new(3, 3)
29
+ monday = Date.today.beginning_of_week
30
+ wednesday = monday + 2.days
31
+ expect(GBWorkDay::Date.from_date(monday, week).work?).to be_falsey
32
+ expect(GBWorkDay::Date.from_date(wednesday, week).work?).to be_truthy
33
+ end
34
+
35
+ it 'should use set week for free? method' do
36
+ week = GBWorkDay::WorkWeek.new(3, 3)
37
+ monday = Date.today.beginning_of_week
38
+ wednesday = monday + 2.days
39
+ expect(GBWorkDay::Date.from_date(monday, week).free?).to be_truthy
40
+ expect(GBWorkDay::Date.from_date(wednesday, week).free?).to be_falsey
41
+ end
42
+
43
+ it 'should use set week for next_work_day? method' do
44
+ week = GBWorkDay::WorkWeek.new(3, 3)
45
+ monday = Date.today.beginning_of_week
46
+ wednesday = monday + 2.days
47
+ expect(GBWorkDay::Date.from_date(monday, week).next_work_day).to eq wednesday
48
+ expect(GBWorkDay::Date.from_date(wednesday, week).next_work_day).to eq (wednesday + 1.day)
49
+ end
50
+
51
+ context 'class methods' do
52
+ it 'should return GBWorkingDay::Date on today' do
53
+ expect(GBWorkDay::Date.today).to be_kind_of GBWorkDay::Date
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'gb_work_day/helpers/time'
3
+ require 'gb_work_day/core_ext/time'
4
+ require 'active_support/time'
5
+
6
+ describe GBWorkDay::Time do
7
+
8
+ it 'should be a subclass of time' do
9
+ expect(GBWorkDay::Time.now).to be_kind_of ::Time
10
+ end
11
+
12
+ it 'should be able to make a copy form other time instance' do
13
+ old_time = ::Time.now
14
+ expect(GBWorkDay::Time.from_time old_time).to be_kind_of GBWorkDay::Time
15
+ expect(GBWorkDay::Time.from_time old_time).to eq old_time
16
+ end
17
+
18
+ it 'should return work day duration on subtraction' do
19
+ monday = Time.now.beginning_of_week
20
+ wednesday = monday + 2.days
21
+ expect(GBWorkDay::Time.from_time(wednesday) - monday).to be_kind_of GBWorkDay::Duration
22
+ expect(GBWorkDay::Time.from_time(wednesday) - GBWorkDay::Time.from_time(monday)).to be_kind_of GBWorkDay::Duration
23
+ expect(GBWorkDay::Time.from_time(wednesday) - 100).to be_kind_of Time
24
+ expect(wednesday - GBWorkDay::Time.from_time(monday)).to be_a_kind_of GBWorkDay::Duration
25
+ end
26
+
27
+ it 'should use set week for work? method' do
28
+ week = GBWorkDay::WorkWeek.new(3, 3)
29
+ monday = Time.now.beginning_of_week
30
+ wednesday = monday + 2.days
31
+ expect(GBWorkDay::Time.from_time(monday, week).work?).to be_falsey
32
+ expect(GBWorkDay::Time.from_time(wednesday, week).work?).to be_truthy
33
+ end
34
+
35
+ it 'should use set week for free? method' do
36
+ week = GBWorkDay::WorkWeek.new(3, 3)
37
+ monday = Time.now.beginning_of_week
38
+ wednesday = monday + 2.days
39
+ expect(GBWorkDay::Time.from_time(monday, week).free?).to be_truthy
40
+ expect(GBWorkDay::Time.from_time(wednesday, week).free?).to be_falsey
41
+ end
42
+
43
+ it 'should use set week for next_work_day? method' do
44
+ week = GBWorkDay::WorkWeek.new(3, 3)
45
+ monday = Time.now.beginning_of_week
46
+ wednesday = monday + 2.days
47
+ expect(GBWorkDay::Time.from_time(monday, week).next_work_day).to eq wednesday
48
+ expect(GBWorkDay::Time.from_time(wednesday, week).next_work_day).to eq (wednesday + 1.day)
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'gb_work_day/interval'
3
+ require 'active_support/time'
4
+
5
+
6
+ describe GBWorkDay::Interval do
7
+ it 'properly calculate work days for interval' do
8
+ week = GBWorkDay::WorkWeek.new(5)
9
+ monday = Date.today.beginning_of_week
10
+ expect(GBWorkDay::Interval.new(monday - 1.day, monday, week: week).duration.work_days).to eq 0
11
+ expect(GBWorkDay::Interval.new(monday - 2.day, monday, week: week).duration.work_days).to eq 0
12
+ expect(GBWorkDay::Interval.new(monday + 1.day, monday, week: week).duration.work_days).to eq -1
13
+ expect(GBWorkDay::Interval.new(monday, monday + 1.day, week: week).duration.work_days).to eq 1
14
+ expect(GBWorkDay::Interval.new(monday, monday + 5.day, week: week).duration.work_days).to eq 5
15
+ expect(GBWorkDay::Interval.new(monday, monday + 7.day, week: week).duration.work_days).to eq 5
16
+ expect(GBWorkDay::Interval.new(monday, monday + 12.day, week: week).duration.work_days).to eq 10
17
+ expect(GBWorkDay::Interval.new(monday, monday + 14.day, week: week).duration.work_days).to eq 10
18
+ end
19
+ end
@@ -0,0 +1,106 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ require 'simplecov'
20
+ SimpleCov.start do
21
+ add_filter '/spec/'
22
+ add_group 'Library core', 'lib/'
23
+ add_group 'Core Extensions', 'lib/gb_work_day/core_ext'
24
+ add_group 'Helpers', 'lib/gb_work_day/helpers'
25
+ end
26
+
27
+ SimpleCov.minimum_coverage 90
28
+
29
+ RSpec.configure do |config|
30
+ # rspec-expectations config goes here. You can use an alternate
31
+ # assertion/expectation library such as wrong or the stdlib/minitest
32
+ # assertions if you prefer.
33
+ config.expect_with :rspec do |expectations|
34
+ # This option will default to `true` in RSpec 4. It makes the `description`
35
+ # and `failure_message` of custom matchers include text for helper methods
36
+ # defined using `chain`, e.g.:
37
+ # be_bigger_than(2).and_smaller_than(4).description
38
+ # # => "be bigger than 2 and smaller than 4"
39
+ # ...rather than:
40
+ # # => "be bigger than 2"
41
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
42
+ end
43
+
44
+ # rspec-mocks config goes here. You can use an alternate test double
45
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
46
+ config.mock_with :rspec do |mocks|
47
+ # Prevents you from mocking or stubbing a method that does not exist on
48
+ # a real object. This is generally recommended, and will default to
49
+ # `true` in RSpec 4.
50
+ mocks.verify_partial_doubles = true
51
+ end
52
+
53
+ # The settings below are suggested to provide a good initial experience
54
+ # with RSpec, but feel free to customize to your heart's content.
55
+ =begin
56
+ # These two settings work together to allow you to limit a spec run
57
+ # to individual examples or groups you care about by tagging them with
58
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
59
+ # get run.
60
+ config.filter_run :focus
61
+ config.run_all_when_everything_filtered = true
62
+
63
+ # Allows RSpec to persist some state between runs in order to support
64
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
65
+ # you configure your source control system to ignore this file.
66
+ config.example_status_persistence_file_path = "spec/examples.txt"
67
+
68
+ # Limits the available syntax to the non-monkey patched syntax that is
69
+ # recommended. For more details, see:
70
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
71
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
73
+ config.disable_monkey_patching!
74
+
75
+ # This setting enables warnings. It's recommended, but in some cases may
76
+ # be too noisy due to issues in dependencies.
77
+ config.warnings = true
78
+
79
+ # Many RSpec users commonly either run the entire suite or an individual
80
+ # file, and it's useful to allow more verbose output when running an
81
+ # individual spec file.
82
+ if config.files_to_run.one?
83
+ # Use the documentation formatter for detailed output,
84
+ # unless a formatter has already been configured
85
+ # (e.g. via a command-line flag).
86
+ config.default_formatter = 'doc'
87
+ end
88
+
89
+ # Print the 10 slowest examples and example groups at the
90
+ # end of the spec run, to help surface which specs are running
91
+ # particularly slow.
92
+ config.profile_examples = 10
93
+
94
+ # Run specs in random order to surface order dependencies. If you find an
95
+ # order dependency and want to debug it, you can fix the order by providing
96
+ # the seed, which is printed after each run.
97
+ # --seed 1234
98
+ config.order = :random
99
+
100
+ # Seed global randomization in this process using the `--seed` CLI option.
101
+ # Setting this allows you to use `--seed` to deterministically reproduce
102
+ # test failures related to randomization by passing the same `--seed` value
103
+ # as the one that triggered the failure.
104
+ Kernel.srand config.seed
105
+ =end
106
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+ require 'gb_work_day/work_week'
3
+ require 'active_support/time'
4
+
5
+ describe GBWorkDay::WorkWeek do
6
+
7
+ context 'work days' do
8
+ it 'should calculates work days for 7 days work and start on monday' do
9
+ week = GBWorkDay::WorkWeek.new(7, 1)
10
+ expect(week.work_days).to eq [1,2,3,4,5,6,7]
11
+ end
12
+
13
+ it 'should calculates work days for 7 days work and start on tuesday' do
14
+ week = GBWorkDay::WorkWeek.new(7, 2)
15
+ expect(week.work_days).to eq [1,2,3,4,5,6,7]
16
+ end
17
+
18
+ it 'should calculates work days for 5 days work week and start on monday' do
19
+ week = GBWorkDay::WorkWeek.new(5, 1)
20
+ expect(week.work_days).to eq [1,2,3,4,5]
21
+ end
22
+
23
+ it 'should calculates work days for 5 days work week and start on tuesday' do
24
+ week = GBWorkDay::WorkWeek.new(5, 2)
25
+ expect(week.work_days).to eq [2,3,4,5,6]
26
+ end
27
+
28
+ it 'should calculates work days for 5 days work week and start on thursday' do
29
+ week = GBWorkDay::WorkWeek.new(5, 4)
30
+ expect(week.work_days).to eq [1,4,5,6,7]
31
+ end
32
+
33
+ it 'should calculates work days for 3 days work week and start on wednesday' do
34
+ week = GBWorkDay::WorkWeek.new(3, 3)
35
+ expect(week.work_days).to eq [3,4,5]
36
+ end
37
+ end
38
+
39
+ context 'free days' do
40
+ it 'should calculates free days for 7 days work and start on any day' do
41
+ week = GBWorkDay::WorkWeek.new(7, rand(6)+1)
42
+ expect(week.free_days).to eq []
43
+ end
44
+
45
+ it 'should calculates free days for 5 days work week and start on monday' do
46
+ week = GBWorkDay::WorkWeek.new(5, 1)
47
+ expect(week.free_days).to eq [6,7]
48
+ end
49
+
50
+ it 'should calculates work days for 5 days work week and start on tuesday' do
51
+ week = GBWorkDay::WorkWeek.new(5, 2)
52
+ expect(week.free_days).to eq [1,7]
53
+ end
54
+
55
+ it 'should calculates work days for 5 days work week and start on thursday' do
56
+ week = GBWorkDay::WorkWeek.new(5, 4)
57
+ expect(week.free_days).to eq [2,3]
58
+ end
59
+
60
+ it 'should calculates work days for 3 days work week and start on wednesday' do
61
+ week = GBWorkDay::WorkWeek.new(3, 3)
62
+ expect(week.free_days).to eq [1,2,6,7]
63
+ end
64
+ end
65
+
66
+ it 'should respond to work_day? if day is a Time' do
67
+ week = GBWorkDay::WorkWeek.new(5, 1)
68
+ expect(week.work_days).to eq [1,2,3,4,5]
69
+ monday = Time.now.beginning_of_week
70
+
71
+ expect(week.work_day? monday).to eq true
72
+
73
+ expect(week.work_day? monday + 1.day).to eq true
74
+ expect(week.work_day? monday + 2.days).to eq true
75
+ expect(week.work_day? monday + 3.days).to eq true
76
+ expect(week.work_day? monday + 4.days).to eq true
77
+ expect(week.work_day? monday + 5.days).to eq false
78
+ expect(week.work_day? monday + 6.days).to eq false
79
+ end
80
+
81
+ it 'should respond to work_day? if day is a Date' do
82
+ week = GBWorkDay::WorkWeek.new(5, 1)
83
+ expect(week.work_days).to eq [1,2,3,4,5]
84
+ monday = Date.today.beginning_of_week
85
+
86
+ expect(week.work_day? monday).to eq true #mondey
87
+ expect(week.work_day? monday + 1.day).to eq true #tuesday
88
+ expect(week.work_day? monday + 2.days).to eq true #wednesday
89
+ expect(week.work_day? monday + 3.days).to eq true #thursday
90
+ expect(week.work_day? monday + 4.days).to eq true #friday
91
+ expect(week.work_day? monday + 5.days).to eq false #saturday
92
+ expect(week.work_day? monday + 6.days).to eq false #sunday
93
+ end
94
+
95
+ it 'should respond to free_day? if day is a Time' do
96
+ week = GBWorkDay::WorkWeek.new(5, 1)
97
+ expect(week.free_days).to eq [6,7]
98
+ monday = Time.now.beginning_of_week
99
+
100
+ expect(week.free_day? monday).to eq false
101
+ expect(week.free_day? monday + 1.day).to eq false
102
+ expect(week.free_day? monday + 2.days).to eq false
103
+ expect(week.free_day? monday + 3.days).to eq false
104
+ expect(week.free_day? monday + 4.days).to eq false
105
+ expect(week.free_day? monday + 5.days).to eq true
106
+ expect(week.free_day? monday + 6.days).to eq true
107
+ end
108
+
109
+ it 'should respond to free_day? if day is a Date' do
110
+ week = GBWorkDay::WorkWeek.new(5, 1)
111
+ expect(week.free_days).to eq [6,7]
112
+ monday = Date.today.beginning_of_week
113
+
114
+ expect(week.free_day? monday).to eq false
115
+ expect(week.free_day? monday + 1.day).to eq false
116
+ expect(week.free_day? monday + 2.days).to eq false
117
+ expect(week.free_day? monday + 3.days).to eq false
118
+ expect(week.free_day? monday + 4.days).to eq false
119
+ expect(week.free_day? monday + 5.days).to eq true
120
+ expect(week.free_day? monday + 6.days).to eq true
121
+ end
122
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gb_work_day
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kacper Kawecki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Library extending Time and Date to do calculations for work days. Unlike
84
+ others libraries it operates on whole days, not hours.
85
+ email:
86
+ - kacper@geniebelt.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".idea/.name"
93
+ - ".idea/encodings.xml"
94
+ - ".idea/gb_working_day.iml"
95
+ - ".idea/misc.xml"
96
+ - ".idea/modules.xml"
97
+ - ".idea/runConfigurations/specs.xml"
98
+ - ".idea/workspace.xml"
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - gb_work_day.gemspec
104
+ - lib/gb_work_day.rb
105
+ - lib/gb_work_day/core_ext.rb
106
+ - lib/gb_work_day/core_ext/date.rb
107
+ - lib/gb_work_day/core_ext/integer.rb
108
+ - lib/gb_work_day/core_ext/time.rb
109
+ - lib/gb_work_day/duration.rb
110
+ - lib/gb_work_day/helpers/date.rb
111
+ - lib/gb_work_day/helpers/time.rb
112
+ - lib/gb_work_day/interval.rb
113
+ - lib/gb_work_day/version.rb
114
+ - lib/gb_work_day/work_week.rb
115
+ - spec/core_ext/date_spec.rb
116
+ - spec/core_ext/integer_spec.rb
117
+ - spec/core_ext/time_spec.rb
118
+ - spec/duration_spec.rb
119
+ - spec/helpers/date_spec.rb
120
+ - spec/helpers/time_spec.rb
121
+ - spec/interval_spec.rb
122
+ - spec/spec_helper.rb
123
+ - spec/work_week_spec.rb
124
+ homepage: https://github.com/GenieBelt/gb-works-day
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.5.1
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Library extending Time and Date to do calculations for work days
148
+ test_files:
149
+ - spec/core_ext/date_spec.rb
150
+ - spec/core_ext/integer_spec.rb
151
+ - spec/core_ext/time_spec.rb
152
+ - spec/duration_spec.rb
153
+ - spec/helpers/date_spec.rb
154
+ - spec/helpers/time_spec.rb
155
+ - spec/interval_spec.rb
156
+ - spec/spec_helper.rb
157
+ - spec/work_week_spec.rb