aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/calendars_controller_spec.rb31
-rw-r--r--spec/features/calendars_spec.rb82
-rw-r--r--spec/models/calendar_spec.rb18
3 files changed, 10 insertions, 121 deletions
diff --git a/spec/controllers/calendars_controller_spec.rb b/spec/controllers/calendars_controller_spec.rb
deleted file mode 100644
index ab3123192..000000000
--- a/spec/controllers/calendars_controller_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-RSpec.describe CalendarsController, type: :controller do
- login_user
- describe 'POST /create' do
-
- context 'legal date' do
- let( :params ){ {
- "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
- "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"19", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
- } }
-
- it 'creates the calendar and redirects to show' do
- expect{ post :create, params }.to change{Calendar.count}.by 1
- expect( response ).to redirect_to( calendar_path( Calendar.last ) )
- end
- end
-
- context 'illegal date' do
- let( :params ){ {
- "calendar"=>{"name"=>"cal", "short_name"=>"cal", "shared"=>"false",
- "date_values_attributes"=>{"1497892917360"=>{"value(3i)"=>"31", "value(2i)"=>"6", "value(1i)"=>"2017", "_destroy"=>""}}}
- } }
-
- it 'does not create the calendar and redircets to new' do
- post :create, params
- expect{ post :create, params }.not_to change{Calendar.count}
- expect( response ).to redirect_to( new_calendar_path )
- end
- end
-
- end
-end
diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb
deleted file mode 100644
index 8c38e7820..000000000
--- a/spec/features/calendars_spec.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-RSpec.describe 'Calendars', type: :feature do
- login_user
-
- let!(:calendars) { Array.new(2) { create :calendar, organisation_id: 1 } }
- let!(:shared_calendar_other_org) { create :calendar, shared: true }
- let!(:unshared_calendar_other_org) { create :calendar }
-
- describe 'index' do
- before(:each) { visit calendars_path }
-
- it 'displays calendars of the current organisation' do
- expect(page).to have_content(calendars.first.short_name)
- # expect(page).to have_content(shared_calendar_other_org.short_name)
- # expect(page).not_to have_content(unshared_calendar_other_org.short_name)
- end
-
- context 'filtering' do
- it 'supports filtering by short name' do
- fill_in 'q[name_or_short_name_cont]', with: calendars.first.short_name
- click_button 'search_btn'
- expect(page).to have_content(calendars.first.short_name)
- expect(page).not_to have_content(calendars.last.short_name)
- end
-
- it 'supports filtering by name' do
- fill_in 'q[name_or_short_name_cont]', with: calendars.first.name
- click_button 'search_btn'
- expect(page).to have_content(calendars.first.name)
- expect(page).not_to have_content(calendars.last.name)
- end
-
-
- it 'supports filtering by shared' do
- shared_calendar = create :calendar, organisation_id: 1, shared: true
- visit calendars_path
- # select I18n.t('true'), from: 'q[shared]'
- find(:css, '#q_shared_true').set(true)
- click_button 'filter_btn'
- expect(page).to have_content(shared_calendar.short_name)
- expect(page).not_to have_content(calendars.first.short_name)
- end
-
- # wip
- # it 'supports filtering by date' do
- # july_calendar = create :calendar, dates: [Date.new(2017, 7, 7)], date_ranges: [Date.new(2017, 7, 15)..Date.new(2017, 7, 30)], organisation_id: 1
- # visit calendars_path
- # select '7', from: 'q_contains_date_3i'
- # select 'juillet', from: 'q_contains_date_2i'
- # select '2017', from: 'q_contains_date_1i'
- # click_button 'filter_btn'
- # expect(page).to have_content(july_calendar.short_name)
- # expect(page).not_to have_content(calendars.first.short_name)
- # select '18', from: 'q_contains_date_3i'
- # select 'juillet', from: 'q_contains_date_2i'
- # select '2017', from: 'q_contains_date_1i'
- # click_button 'filter_btn'
- # expect(page).to have_content(july_calendar.short_name)
- # expect(page).not_to have_content(calendars.first.short_name)
- # end
- end
- end
-
- describe 'show' do
- it 'displays calendar' do
- visit calendar_path(calendars.first)
- expect(page).to have_content(calendars.first.name)
- end
- end
-
- describe 'create', :wip do
- before do
- visit new_calendar_path
-
- end
- it 'with correct date' do
- require 'pry'
- binding.pry
-
- end
-
- end
-end
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 33d9676cd..6a2b24011 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -42,10 +42,10 @@ RSpec.describe Calendar, :type => :model do
subject { period }
def period(attributes = {})
- return @period if attributes.empty? and @period
- Calendar::Period.new(attributes).tap do |period|
- @period = period if attributes.empty?
- end
+ @__period__ ||= {}
+ @__period__.fetch(attributes){
+ @__period__[attributes] = Calendar::Period.new(attributes)
+ }
end
it 'should support mark_for_destruction (required by cocoon)' do
@@ -125,9 +125,9 @@ RSpec.describe Calendar, :type => :model do
subject { date_value }
def date_value(attributes = {})
- return @date_value if attributes.empty? and @date_value
- Calendar::DateValue.new(attributes).tap do |date_value|
- @date_value = date_value if attributes.empty?
+ @__date_values__ ||= Hash.new
+ @__date_values__.fetch(attributes) do
+ @__date_values__[attributes] = Calendar::DateValue.new(attributes)
end
end
@@ -150,7 +150,9 @@ RSpec.describe Calendar, :type => :model do
expect(date_value(value: '2017-01-03').value).to eq(Date.new(2017,01,03))
end
- it { is_expected.to validate_presence_of(:value) }
+ it 'validates presence' do
+ is_expected.to validate_presence_of(:value)
+ end
end
end