clndr-rails 1.2.5.1 → 1.2.5.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +11 -2
  3. data/lib/clndr-rails.rb +196 -171
  4. data/lib/clndr-rails/config.rb +48 -34
  5. data/lib/clndr-rails/engine.rb +1 -0
  6. data/lib/clndr-rails/errors.rb +1 -0
  7. data/lib/clndr-rails/helpers.rb +13 -13
  8. data/lib/clndr-rails/templates.rb +46 -43
  9. data/lib/clndr-rails/version.rb +1 -1
  10. data/test/dummy/app/controllers/base_controller.rb +5 -5
  11. data/test/dummy/app/views/base/index.html.erb +5 -1
  12. data/test/dummy/config/initializers/clndr.rb +23 -25
  13. data/test/dummy/log/development (/320/232/320/276/320/275/321/204/320/273/320/270/320/272/321/202/321/203/321/216/321/211/320/260/321/217 /320/272/320/276/320/277/320/270/321/217 /321/201 /320/272/320/276/320/274/320/277/321/214/321/216/321/202/320/265/321/200/320/260 DELTAPC2 2014-12-25).log" +19726 -0
  14. data/test/dummy/log/development.log +236 -0
  15. data/test/dummy/log/test.log +12484 -0
  16. data/test/dummy/spec/rails_helper.rb +2 -2
  17. data/test/dummy/spec/views/base/index.html.erb_spec.rb +4 -4
  18. data/test/dummy/test/helpers/base_helper_test.rb +1 -0
  19. data/test/dummy/tmp/cache/assets/development/sprockets/003c68cd1f3ba2d6344147bb52d8fd1a +0 -0
  20. data/test/dummy/tmp/cache/assets/development/sprockets/08b993c8e83ad57a4ecb8d753b4620d5 +0 -0
  21. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  22. data/test/dummy/tmp/cache/assets/development/sprockets/1d658adc7cb09c209c423c9138dbacee +0 -0
  23. data/test/dummy/tmp/cache/assets/development/sprockets/28cfd59c37a42a9ea808d622b0177c86 +0 -0
  24. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  25. data/test/dummy/tmp/cache/assets/development/sprockets/4ad6cd41e5b645f9ceef10b1e3baea77 +0 -0
  26. data/test/dummy/tmp/cache/assets/development/sprockets/6c33e774b86f9ef5ba24ffbe52bed674 +0 -0
  27. data/test/dummy/tmp/cache/assets/development/sprockets/7b51783beb0f6f17617f87ef5d2688e3 +0 -0
  28. data/test/dummy/tmp/cache/assets/development/sprockets/9334f44096c23e8904784b524e6ae750 +0 -0
  29. data/test/dummy/tmp/cache/assets/development/sprockets/954c1c7328e5b9c43abd84f4981286c7 +0 -0
  30. data/test/dummy/tmp/cache/assets/development/sprockets/9bd8392ddf2b52be4b455e52a628d169 +0 -0
  31. data/test/dummy/tmp/cache/assets/development/sprockets/9c89c900cca1bf92a5f29c304d323256 +0 -0
  32. data/test/dummy/tmp/cache/assets/development/sprockets/9e158358644b7e1cbee43defd7d7b449 +0 -0
  33. data/test/dummy/tmp/cache/assets/development/sprockets/a086b63b827c2bdef684cc4985c925fc +0 -0
  34. data/test/dummy/tmp/cache/assets/development/sprockets/a62be18dea33018456ea9b72b4a9e10b +0 -0
  35. data/test/dummy/tmp/cache/assets/development/sprockets/ad861213dbd41ab02600f740c9bb1dee +0 -0
  36. data/test/dummy/tmp/cache/assets/development/sprockets/ae0ae68c837285b67a4fc1df4dddb939 +0 -0
  37. data/test/dummy/tmp/cache/assets/development/sprockets/c744c093e347d6c90bc75206f502a48e +0 -0
  38. data/test/dummy/tmp/cache/assets/development/sprockets/cc517e4ba5ef452b08d1ab48925b952d +0 -0
  39. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  40. data/test/dummy/tmp/cache/assets/development/sprockets/dc767a0bb27fb390899cd7e6ff34b310 +0 -0
  41. data/test/dummy/tmp/cache/assets/development/sprockets/e59e1f3e795e9486fffbc3b4ad0baaca +0 -0
  42. data/test/dummy/tmp/cache/assets/development/sprockets/e7296c70ca399cdcc73806b4a9481fde +0 -0
  43. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  44. data/test/dummy/tmp/pids/server.pid +1 -1
  45. data/test/spec/clnd-rails_spec.rb +29 -0
  46. data/test/spec/configuration_spec.rb +123 -0
  47. data/test/spec/events_spec.rb +63 -0
  48. data/test/spec/html_spec.rb +200 -0
  49. data/test/spec/rails_helper.rb +0 -0
  50. data/test/spec/spec_helper.rb +16 -0
  51. data/test/spec/templates_spec.rb +71 -0
  52. metadata +54 -3
  53. data/config/routes.rb +0 -2
@@ -1,7 +1,7 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- ENV["RAILS_ENV"] ||= 'test'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
3
  require 'spec_helper'
4
- require File.expand_path("../../config/environment", __FILE__)
4
+ require File.expand_path('../../config/environment', __FILE__)
5
5
  require 'rspec/rails'
6
6
  # Add additional requires below this line. Rails is not loaded until this point!
7
7
 
@@ -1,16 +1,16 @@
1
1
  require 'rails_helper'
2
2
 
3
- RSpec.describe "base/index.html.erb", :js => true do
4
- it "should show calendar" do
3
+ RSpec.describe 'base/index.html.erb', :js => true do
4
+ it 'should show calendar' do
5
5
  visit root_path
6
6
  expect(page).to have_css('div.clndr')
7
7
  end
8
8
 
9
- it "should have full calendar" do
9
+ it 'should have full calendar' do
10
10
  expect(page).to have_css('div.event-listing')
11
11
  end
12
12
 
13
- it "should have blank calendar" do
13
+ it 'should have blank calendar' do
14
14
  expect(page).to have_selector('table')
15
15
  end
16
16
 
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class BaseHelperTest < ActionView::TestCase
4
+
4
5
  end
@@ -1 +1 @@
1
- 7812
1
+ 11180
@@ -0,0 +1,29 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe Clndr do
4
+ describe 'Create and find calendar method' do
5
+ before :all do
6
+ Clndr.new(:test1)
7
+ Clndr.new(:test2)
8
+ end
9
+
10
+ it '#new should add calendar to calendar bean' do
11
+ expect(Clndr.calendar_basket[:test1]).to be_instance_of Clndr
12
+ expect(Clndr.calendar_basket[:test2]).to be_instance_of Clndr
13
+ expect(Clndr.calendar_basket[:test3]).to be_nil
14
+ end
15
+
16
+ it '#get_calendar should return calendar' do
17
+ expect(Clndr.get_calendar(:test1)).to be_instance_of Clndr
18
+ end
19
+
20
+ it '#get_calendar should raise exception if calendar not found' do
21
+ expect{Clndr.get_calendar(:undefined)}.to raise_error(Clndr::Error::CalendarNotFound)
22
+ end
23
+
24
+ it '#new should create calendar with string name' do
25
+ Clndr.new('test calendar')
26
+ expect(Clndr.get_calendar('test calendar')).to be_instance_of Clndr
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,123 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe 'Clndr configuration' do
4
+ shared_examples 'configurable' do
5
+
6
+ it 'should be configurable' do
7
+ expect(@calendar.template).to eq(Clndr::Template::SIMPLE)
8
+ end
9
+
10
+ it 'should get week_offset from config' do
11
+ expect(@calendar.week_offset).to eq(0)
12
+ end
13
+
14
+ it 'should get start_with_month config' do
15
+ expect(@calendar.start_with_month).to eq('2014-12-31')
16
+ end
17
+
18
+ it 'should get days_of_week config' do
19
+ expect(@calendar.days_of_the_week.first).to eq('x')
20
+ end
21
+
22
+ it 'should get click_events config' do
23
+ expect(@calendar.click_event[:click]).to include('js_function')
24
+ end
25
+
26
+ it 'should get targets config' do
27
+ expect(@calendar.target[:nextButton]).to include('class')
28
+ end
29
+
30
+ it 'should get show_adjacent_months config' do
31
+ expect(@calendar.show_adjacent_months).to be_falsey
32
+ end
33
+
34
+ it 'should get adjacent_days_change_month config' do
35
+ expect(@calendar.adjacent_days_change_month).to be_truthy
36
+ end
37
+
38
+ it 'should get done_rendering config' do
39
+ expect(@calendar.done_rendering).to include('callbaks_function')
40
+ end
41
+
42
+ it 'should get constraints_start config' do
43
+ expect(@calendar.constraints_start).to eq('2014-12-31')
44
+ end
45
+
46
+ it 'should get constraints_end config' do
47
+ expect(@calendar.constraints_end).to eq('2014-12-31')
48
+ end
49
+
50
+ it 'should get force_six_rows config' do
51
+ expect(@calendar.force_six_rows).to be_falsey
52
+ end
53
+ end
54
+
55
+ context 'init' do
56
+ before do
57
+ Clndr.configure do |config|
58
+ config.template = Clndr::Template::SIMPLE
59
+ config.week_offset = false
60
+ config.start_with_month = '2014-12-31'
61
+ config.days_of_the_week =['x'] * 7
62
+ config.click_events do |event|
63
+ event[:click] ='some_js_function(){}'
64
+ end
65
+ config.targets do |target|
66
+ target[:nextButton] = '.some_class'
67
+ end
68
+ config.show_adjacent_months = false
69
+ config.adjacent_days_change_month = true
70
+ config.done_rendering = 'some_callbaks_function(){}'
71
+ config.constraints_start = '2014-12-31'
72
+ config.constraints_end = '2014-12-31'
73
+ config.force_six_rows = false
74
+ end
75
+
76
+ @calendar = Clndr.new(:test)
77
+ end
78
+ it_should_behave_like 'configurable'
79
+
80
+ it 'should convert week_offset config to digit' do
81
+ Clndr.configure{|config| config.week_offset = true}
82
+ @calendar = Clndr.new :test
83
+ expect(@calendar.week_offset).to eq(1)
84
+ end
85
+ end
86
+
87
+ context 'dinamycaly change config' do
88
+ before :each do
89
+ @calendar = Clndr.new(:test)
90
+ @calendar.template = Clndr::Template::SIMPLE
91
+ @calendar.week_offset = false
92
+ @calendar.start_with_month = '2014-12-31'
93
+ @calendar.days_of_the_week =['x'] * 7
94
+ @calendar.click_event[:click] ='some_js_function(){}'
95
+ @calendar.target[:nextButton] = '.some_class'
96
+ @calendar.show_adjacent_months = false
97
+ @calendar.adjacent_days_change_month = true
98
+ @calendar.done_rendering = 'some_callbaks_function(){}'
99
+ @calendar.constraints_start = '2014-12-31'
100
+ @calendar.constraints_end = '2014-12-31'
101
+ @calendar.force_six_rows = false
102
+ end
103
+ it_should_behave_like 'configurable'
104
+
105
+ it 'should convert week_offset config to digit' do
106
+ @calendar.week_offset = true
107
+ expect(@calendar.week_offset).to eq(1)
108
+ end
109
+ end
110
+
111
+ it 'should fall to default settings when #defaul_settings call' do
112
+ Clndr.default_settings
113
+ expect(Clndr.new(:test).template).to eq(Clndr::Template::BLANK)
114
+ end
115
+
116
+ it 'should raise exception if date format wrong' do
117
+ expect{Clndr.configure{|config| config.start_with_month = 'dsf'}}.to raise_error(Clndr::Error::WrongDateFormat)
118
+ expect{Clndr.configure{|config| config.constraints_start = 'dsf'}}.to raise_error(Clndr::Error::WrongDateFormat)
119
+ expect{Clndr.configure{|config| config.constraints_end = 'dsf'}}.to raise_error(Clndr::Error::WrongDateFormat)
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,63 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe 'Clndr event' do
4
+ before do
5
+ @test = Clndr.new :test
6
+ end
7
+
8
+ shared_examples 'event' do
9
+ it "should receive Date and Title" do
10
+ @test.send(method_for_test,*args)
11
+ expect(@test.events.length).to eq(1)
12
+ end
13
+
14
+ it "can receive other_data" do
15
+ @test.send(method_for_test,*args,info:'info',msg:'msg',address:'adress')
16
+ expect(@test.events.first.has_key?(:info)).to be_truthy
17
+ expect(@test.events.first.has_key?(:msg)).to be_truthy
18
+ expect(@test.events.first.has_key?(:address)).to be_truthy
19
+ end
20
+
21
+
22
+ it " should add event to events array" do
23
+ @test.send(method_for_test,*args)
24
+ @test.send(method_for_test,*args,some_info:'info')
25
+ expect(@test.events.length).to eq(2)
26
+ end
27
+
28
+ it 'should raise exeption when recive wrong data format' do
29
+ expect{@test.send(method_for_test,*wrong_args)}.to raise_error(Clndr::Error::WrongDateFormat)
30
+ end
31
+ end
32
+ context 'add event'do
33
+ it_should_behave_like 'event' do
34
+ let(:method_for_test){:add_event}
35
+ let(:args){[Time.now,'Title']}
36
+ let(:wrong_args){['wrong date','Title']}
37
+ end
38
+ end
39
+
40
+ context 'add multiday event'do
41
+ it_should_behave_like 'event' do
42
+ let(:method_for_test){:add_multiday_event}
43
+ let(:args){[Time.now,Time.now,'Title']}
44
+ let(:wrong_args){['wrong date','wrong date','Title']}
45
+ end
46
+ end
47
+
48
+ context 'build events string' do
49
+ it '.build_events should delete elements from events array' do
50
+ @test.add_event(Time.now,'test1')
51
+ @test.add_event(Time.now,'test2',some_info:'info')
52
+ @test.send(:build_events)
53
+ expect(@test.events.length).to eq(0)
54
+ end
55
+
56
+ it 'should contain multiDayEvents if calendar contain multiday event' do
57
+ @test.add_multiday_event Time.now, Time.now, 'Title', spme_info:'info'
58
+ expect(@test.view).to include('multiDayEvents:')
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,200 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe 'Clndr generate html' do
4
+ before do
5
+ Clndr.default_settings
6
+ @test = Clndr.new(:test)
7
+ end
8
+
9
+ it 'by .view method' do
10
+ expect(@test.view).to include('id="test-clndr"')
11
+ end
12
+
13
+ it 'by .view method with html_options' do
14
+ expect(@test.view(id:'some-test-id')).to include('some-test-id')
15
+ expect(@test.view(id:'some-test-id', class:'some-test-class')).to include('some-test-class')
16
+ end
17
+
18
+ it 'by show_calendar method' do
19
+ expect(show_calendar(:test)).to eq(@test.view)
20
+ end
21
+
22
+ it 'by show_calendar with html_options' do
23
+ expect(show_calendar(:test,id:'some-test-id',class:'some-test-class')).to eq(@test.view(id:'some-test-id',class:'some-test-class'))
24
+ end
25
+
26
+ context 'with clndr option' do
27
+ shared_examples 'valid generator' do
28
+
29
+ it 'return nothing if parametr is default' do
30
+ expect(@test.view).not_to include("#{parameter}:")
31
+ end
32
+
33
+ it 'return valid parametr' do
34
+ @test.send(option,value)
35
+ expect(@test.view).to include("#{parameter}:#{valid_value}")
36
+ end
37
+
38
+ end
39
+
40
+ context 'template' do
41
+ it_should_behave_like 'valid generator' do
42
+ let(:option){ :template=}
43
+ let(:value){Clndr::Template::SIMPLE}
44
+ let(:valid_value){value}
45
+ let(:parameter){'template'}
46
+ end
47
+ end
48
+
49
+ context 'days_of_the_week' do
50
+ it_should_behave_like 'valid generator' do
51
+ let(:option){ :days_of_the_week=}
52
+ let(:value){['x']*6}
53
+ let(:valid_value){value}
54
+ let(:parameter){'daysOfTheWeek'}
55
+ end
56
+ end
57
+
58
+ context 'show_adjacent_months' do
59
+ it_should_behave_like 'valid generator' do
60
+ let(:option){ :show_adjacent_months=}
61
+ let(:value){false}
62
+ let(:valid_value){value}
63
+ let(:parameter){'showAdjacentMonths'}
64
+ end
65
+ end
66
+
67
+ context 'adjacent_days_change_month' do
68
+ it_should_behave_like 'valid generator' do
69
+ let(:option){ :adjacent_days_change_month=}
70
+ let(:value){Time.now}
71
+ let(:valid_value){value}
72
+ let(:parameter){'adjacentDaysChangeMonth'}
73
+ end
74
+ end
75
+
76
+ context 'done_rendering' do
77
+ it_should_behave_like 'valid generator' do
78
+ let(:option){ :done_rendering=}
79
+ let(:value){'jsfunc(){}'}
80
+ let(:valid_value){value}
81
+ let(:parameter){'doneRendering'}
82
+ end
83
+ end
84
+
85
+ context 'constraints_end' do
86
+ it_should_behave_like 'valid generator' do
87
+ let(:option){ :constraints_end=}
88
+ let(:value){Time.now}
89
+ let(:valid_value){" {endDate:'#{Time.now.strftime('%F')}'"}
90
+ let(:parameter){'constraints'}
91
+ end
92
+ end
93
+
94
+ context 'constraints_start' do
95
+ it_should_behave_like 'valid generator' do
96
+ let(:option){ :constraints_start=}
97
+ let(:value){Time.now}
98
+ let(:valid_value){" {startDate:'#{Time.now.strftime('%F')}'"}
99
+ let(:parameter){'constraints'}
100
+ end
101
+ end
102
+
103
+ context 'click_events' do
104
+ it 'return nothing if parametr is default' do
105
+ expect(@test.view).not_to include('clickEvent')
106
+ end
107
+
108
+ it 'return valid parametr' do
109
+ @test.click_event[:click]='some_js(){}'
110
+ expect(@test.view).to include('clickEvents: {click:some_js(){},}')
111
+ end
112
+ end
113
+
114
+ context 'targets' do
115
+ it 'return nothing if parametr is default' do
116
+ expect(@test.view).not_to include('targets')
117
+ end
118
+
119
+ it 'return valid parametr' do
120
+ @test.target[:nextButton]='.class'
121
+ expect(@test.view).to include("targets: {nextButton:'.class'")
122
+ end
123
+ end
124
+
125
+ context 'force_six_rows' do
126
+ it 'return true if parametr is default' do
127
+ expect(@test.view).to include('forceSixRows:true')
128
+ end
129
+
130
+ it 'return nothing if false' do
131
+ @test.force_six_rows= false
132
+ expect(@test.view).not_to include('forceSixRows:')
133
+ end
134
+ end
135
+
136
+ context 'week_offset' do
137
+ it 'return 1 if parametr is default' do
138
+ expect(@test.view).to include('weekOffset:1')
139
+ end
140
+
141
+ it 'return nothing if 0' do
142
+ @test.week_offset = false
143
+ expect(@test.view).not_to include('weekOffset:0')
144
+ end
145
+ end
146
+
147
+ context 'event' do
148
+ it 'should havent events if events not add' do
149
+ expect(@test.view).not_to include('events:')
150
+ end
151
+ end
152
+ end
153
+
154
+ context 'Link helpers' do
155
+ before :all do
156
+ Clndr.new :helpers
157
+ end
158
+ shared_examples 'navigate link' do
159
+ it 'genearete link' do
160
+ expect(self.send(link_type,:helpers,link_type.to_s)).to include("helpers.#{js}")
161
+ end
162
+ it 'generate link with some html_options' do
163
+ expect(self.send(link_type,:helpers,link_type.to_s,style:'color:red;')).to include('style="color:red;"')
164
+ end
165
+
166
+ it 'generate link with available CLNDR callbacks' do
167
+ expect(self.send(link_type,:helpers,link_type.to_s){true}).to include("withCallbacks: true")
168
+ end
169
+ end
170
+
171
+ context 'next_month_link' do
172
+ it_should_behave_like 'navigate link' do
173
+ let(:link_type){:next_month_link}
174
+ let(:js){'forward'}
175
+ end
176
+ end
177
+
178
+ context 'previous_month_link' do
179
+ it_should_behave_like 'navigate link' do
180
+ let(:link_type){:previous_month_link}
181
+ let(:js){'back'}
182
+ end
183
+ end
184
+
185
+ context 'next_year_link' do
186
+ it_should_behave_like 'navigate link' do
187
+ let(:link_type){:next_year_link}
188
+ let(:js){'nextYear'}
189
+ end
190
+ end
191
+
192
+ context 'previous_year_link' do
193
+ it_should_behave_like 'navigate link' do
194
+ let(:link_type){:previous_year_link}
195
+ let(:js){'previousYear'}
196
+ end
197
+ end
198
+ end
199
+
200
+ end