aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuc Donnet2017-09-27 09:56:59 +0200
committerLuc Donnet2017-09-27 09:56:59 +0200
commit16fc6a184311c0ab5e1463398b91f8a716bcf4db (patch)
treeeea2b4b703c6e7960077a0ad1f1b61e079822950 /spec
parent7ec5867ec7bd7365bb4c97d7d4c1bdc2cf580bc2 (diff)
parent28a42fb19174eafee38fe3c5f8fa58f89991f44a (diff)
downloadchouette-core-16fc6a184311c0ab5e1463398b91f8a716bcf4db.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/imports_controller_spec.rb9
-rw-r--r--spec/javascripts/time_table/actions_spec.js36
-rw-r--r--spec/javascripts/time_table/reducers/modal_spec.js8
-rw-r--r--spec/javascripts/time_table/reducers/pagination_spec.js26
-rw-r--r--spec/javascripts/time_table/reducers/timetable_spec.js147
-rw-r--r--spec/lib/model_attribute_spec.rb111
-rw-r--r--spec/models/chouette/vehicle_journey_at_stop_spec.rb2
-rw-r--r--spec/models/referential_spec.rb1
-rw-r--r--spec/models/referential_suite_spec.rb5
-rw-r--r--spec/policies/api_key_policy_spec.rb4
-rw-r--r--spec/policies/import_policy_spec.rb41
-rw-r--r--spec/policies/referential_policy_spec.rb8
-rw-r--r--spec/support/permissions.rb1
-rw-r--r--spec/support/pundit/policies.rb17
-rw-r--r--spec/support/pundit/shared_examples.rb8
15 files changed, 368 insertions, 56 deletions
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
index f07190496..22be9f6ed 100644
--- a/spec/controllers/imports_controller_spec.rb
+++ b/spec/controllers/imports_controller_spec.rb
@@ -5,10 +5,16 @@ RSpec.describe ImportsController, :type => :controller do
let(:import) { create :import, workbench: workbench }
describe 'GET #new' do
- it 'should be successful' do
+ it 'should be successful if authorized' do
get :new, workbench_id: workbench.id
expect(response).to be_success
end
+
+ it 'should be unsuccessful unless authorized' do
+ remove_permissions('imports.create', from_user: @user, save: true)
+ get :new, workbench_id: workbench.id
+ expect(response).not_to be_success
+ end
end
describe 'GET #download' do
@@ -18,4 +24,5 @@ RSpec.describe ImportsController, :type => :controller do
expect( response.body ).to eq(import.file.read)
end
end
+
end
diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js
index f052aeece..a7344586d 100644
--- a/spec/javascripts/time_table/actions_spec.js
+++ b/spec/javascripts/time_table/actions_spec.js
@@ -171,28 +171,52 @@ describe('actions', () => {
expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas, timetableInDates, error)).toEqual(expectedAction)
})
- it('should create an action to include date in period', () => {
+ it('should create an action to add an included date', () => {
let index = 1
let date = actions.formatDate(new Date)
const expectedAction = {
- type: 'INCLUDE_DATE_IN_PERIOD',
+ type: 'ADD_INCLUDED_DATE',
index,
dayTypes,
date
}
- expect(actions.includeDateInPeriod(index, dayTypes, date)).toEqual(expectedAction)
+ expect(actions.addIncludedDate(index, dayTypes, date)).toEqual(expectedAction)
})
- it('should create an action to exclude date from period', () => {
+ it('should create an action to remove an included dat', () => {
let index = 1
let date = actions.formatDate(new Date)
const expectedAction = {
- type: 'EXCLUDE_DATE_FROM_PERIOD',
+ type: 'REMOVE_INCLUDED_DATE',
index,
dayTypes,
date
}
- expect(actions.excludeDateFromPeriod(index, dayTypes, date)).toEqual(expectedAction)
+ expect(actions.removeIncludedDate(index, dayTypes, date)).toEqual(expectedAction)
+ })
+
+ it('should create an action to add an excluded date in period', () => {
+ let index = 1
+ let date = actions.formatDate(new Date)
+ const expectedAction = {
+ type: 'ADD_EXCLUDED_DATE',
+ index,
+ dayTypes,
+ date
+ }
+ expect(actions.addExcludedDate(index, dayTypes, date)).toEqual(expectedAction)
+ })
+
+ it('should create an action to remove an excluded date from period', () => {
+ let index = 1
+ let date = actions.formatDate(new Date)
+ const expectedAction = {
+ type: 'REMOVE_EXCLUDED_DATE',
+ index,
+ dayTypes,
+ date
+ }
+ expect(actions.removeExcludedDate(index, dayTypes, date)).toEqual(expectedAction)
})
it('should create an action to open confirm modal', () => {
diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascripts/time_table/reducers/modal_spec.js
index 570eb85ed..05d58a138 100644
--- a/spec/javascripts/time_table/reducers/modal_spec.js
+++ b/spec/javascripts/time_table/reducers/modal_spec.js
@@ -171,12 +171,14 @@ describe('modal reducer', () => {
let ttperiods = []
let ttdates = []
+ let metas = []
expect(
modalReducer(state, {
type: 'VALIDATE_PERIOD_FORM',
modalProps : modProps,
timeTablePeriods: ttperiods,
+ metas: metas,
timetableInDates: ttdates,
error: 'La date de départ doit être antérieure à la date de fin'
})
@@ -289,9 +291,12 @@ describe('modal reducer', () => {
index: false,
error: ''
}
- let ttperiods3 = []
+ let ttperiods3 = []
let ttdates3 = [{date: "2017-08-04", include_date: true}]
+ let metas = {
+ day_types: [true,true,true,true,true,true,true]
+ }
let newModalProps3 = {
active: true,
@@ -315,6 +320,7 @@ describe('modal reducer', () => {
modalProps : modProps3,
timeTablePeriods: ttperiods3,
timetableInDates: ttdates3,
+ metas: metas,
error: "Une période ne peut chevaucher une date dans un calendrier"
})
).toEqual(Object.assign({}, state3, {modalProps: newModalProps3}))
diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascripts/time_table/reducers/pagination_spec.js
index 5da58427e..3c1edb9c5 100644
--- a/spec/javascripts/time_table/reducers/pagination_spec.js
+++ b/spec/javascripts/time_table/reducers/pagination_spec.js
@@ -76,20 +76,38 @@ describe('pagination reducer', () => {
).toEqual(Object.assign({}, state, {currentPage : page, stateChanged: false}))
})
- it('should handle INCLUDE_DATE_IN_PERIOD', () => {
+ it('should handle ADD_INCLUDED_DATE', () => {
expect(
paginationReducer(state, {
- type: 'INCLUDE_DATE_IN_PERIOD'
+ type: 'ADD_INCLUDED_DATE'
})
).toEqual(Object.assign({}, state, {stateChanged: true}))
})
- it('should handle EXCLUDE_DATE_FROM_PERIOD', () => {
+
+ it('should handle REMOVE_INCLUDED_DATE', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'REMOVE_INCLUDED_DATE'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+
+ it('should handle ADD_EXCLUDED_DATE', () => {
expect(
paginationReducer(state, {
- type: 'EXCLUDE_DATE_FROM_PERIOD'
+ type: 'ADD_EXCLUDED_DATE'
})
).toEqual(Object.assign({}, state, {stateChanged: true}))
})
+
+ it('should handle REMOVE_EXCLUDED_DATE', () => {
+ expect(
+ paginationReducer(state, {
+ type: 'REMOVE_EXCLUDED_DATE'
+ })
+ ).toEqual(Object.assign({}, state, {stateChanged: true}))
+ })
+
it('should handle DELETE_PERIOD', () => {
expect(
paginationReducer(state, {
diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js
index 6585a78a0..21f6d236d 100644
--- a/spec/javascripts/time_table/reducers/timetable_spec.js
+++ b/spec/javascripts/time_table/reducers/timetable_spec.js
@@ -6,14 +6,13 @@ const dispatch = function(){}
let arrDayTypes = [true, true, true, true, true, true, true]
let strDayTypes = 'LuMaMeJeVeSaDi'
let time_table_periods = [{"id":261,"period_start":"2017-02-23","period_end":"2017-03-05"},{"id":262,"period_start":"2017-03-15","period_end":"2017-03-25"},{"id":263,"period_start":"2017-04-04","period_end":"2017-04-14"},{"id":264,"period_start":"2017-04-24","period_end":"2017-05-04"},{"id":265,"period_start":"2017-05-14","period_end":"2017-05-24"}]
+let time_table_dates = []
let current_periode_range = "2017-05-01"
let periode_range = ["2014-05-01","2014-06-01","2014-07-01","2014-08-01","2014-09-01","2014-10-01","2014-11-01","2014-12-01","2015-01-01","2015-02-01","2015-03-01","2015-04-01","2015-05-01","2015-06-01","2015-07-01","2015-08-01","2015-09-01","2015-10-01","2015-11-01","2015-12-01","2016-01-01","2016-02-01","2016-03-01","2016-04-01","2016-05-01","2016-06-01","2016-07-01","2016-08-01","2016-09-01","2016-10-01","2016-11-01","2016-12-01","2017-01-01","2017-02-01","2017-03-01","2017-04-01","2017-05-01","2017-06-01","2017-07-01","2017-08-01","2017-09-01","2017-10-01","2017-11-01","2017-12-01","2018-01-01","2018-02-01","2018-03-01","2018-04-01","2018-05-01","2018-06-01","2018-07-01","2018-08-01","2018-09-01","2018-10-01","2018-11-01","2018-12-01","2019-01-01","2019-02-01","2019-03-01","2019-04-01","2019-05-01","2019-06-01","2019-07-01","2019-08-01","2019-09-01","2019-10-01","2019-11-01","2019-12-01","2020-01-01","2020-02-01","2020-03-01","2020-04-01","2020-05-01"]
let current_month = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false}]
let newCurrentMonth = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false,"in_periods":false}]
-let time_table_dates = []
-
let json = {
current_month: current_month,
current_periode_range: current_periode_range,
@@ -46,7 +45,7 @@ describe('timetable reducer with empty state', () => {
current_periode_range: current_periode_range,
periode_range: periode_range,
time_table_periods: time_table_periods,
- time_table_dates: time_table_dates
+ time_table_dates: []
}
expect(
timetableReducer(state, {
@@ -125,24 +124,46 @@ describe('timetable reducer with filled state', () => {
).toEqual(Object.assign({}, state, {current_periode_range: newPage}))
})
- it('should handle DELETE_PERIOD', () => {
- state.time_table_periods[0].deleted = true
+ it('should handle DELETE_PERIOD and remove excluded days that were in period', () => {
+ state.time_table_dates.push({date: "2017-05-01", in_out: false})
+ state.current_month[0].excluded_date = true
+ state.time_table_periods[3].deleted = true
+
+ let begin = new Date(state.time_table_periods[3].period_start)
+ let end = new Date(state.time_table_periods[3].period_end)
+
+ let newState = Object.assign({}, state, {
+ time_table_dates: [],
+ current_month: state.current_month.map((d, i) => {
+ if (new Date(d.date) >= begin && new Date(d.date) <= end) {
+ d.excluded_date = false
+ d.in_periods = false
+ }
+ return d
+ })
+ })
expect(
timetableReducer(state, {
type: 'DELETE_PERIOD',
- index: 0,
+ index: 3,
dayTypes: arrDayTypes
})
- ).toEqual(state)
+ ).toEqual(newState)
})
- it('should handle INCLUDE_DATE_IN_PERIOD and add in_day if TT doesnt have it', () => {
+ it('should handle ADD_INCLUDED_DATE', () => {
let newDates = state.time_table_dates.concat({date: "2017-05-05", in_out: true})
- let newState = Object.assign({}, state, {time_table_dates: newDates})
- state.current_month[4].include_date = true
+
+ let newCM = newCurrentMonth.map((d,i) => {
+ if (i == 4) d.include_date = true
+ return d
+ })
+
+ let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM})
+
expect(
timetableReducer(state, {
- type: 'INCLUDE_DATE_IN_PERIOD',
+ type: 'ADD_INCLUDED_DATE',
index: 4,
dayTypes: arrDayTypes,
date: "2017-05-05"
@@ -150,13 +171,20 @@ describe('timetable reducer with filled state', () => {
).toEqual(newState)
})
- it('should handle INCLUDE_DATE_IN_PERIOD and remove in_day if TT has it', () => {
+ it('should handle REMOVE_INCLUDED_DATE', () => {
state.current_month[4].include_date = true
state.time_table_dates.push({date: "2017-05-05", in_out: true})
- let newState = Object.assign({}, state, {time_table_dates: []})
+
+ let newCM = newCurrentMonth.map((d,i) => {
+ if (i == 4) d.include_date = false
+ return d
+ })
+
+ let newDates = state.time_table_dates.filter(d => d.date != "2017-05-05" && d.in_out != true )
+ let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM})
expect(
timetableReducer(state, {
- type: 'INCLUDE_DATE_IN_PERIOD',
+ type: 'REMOVE_INCLUDED_DATE',
index: 4,
dayTypes: arrDayTypes,
date: "2017-05-05"
@@ -164,13 +192,22 @@ describe('timetable reducer with filled state', () => {
).toEqual(newState)
})
- it('should handle EXCLUDE_DATE_FROM_PERIOD and add out_day if TT doesnt have it', () => {
+ it('should handle ADD_EXCLUDED_DATE', () => {
let newDates = state.time_table_dates.concat({date: "2017-05-01", in_out: false})
- let newState = Object.assign({}, state, {time_table_dates: newDates})
- state.current_month[0].excluded_date = true
+
+ let newCM = newCurrentMonth.map((d,i) => {
+ if (i == 0){
+ d.include_date = false
+ d.excluded_date = true
+ }
+ return d
+ })
+
+ let newState = Object.assign({}, state, {time_table_dates: newDates, current_month: newCM})
+
expect(
timetableReducer(state, {
- type: 'EXCLUDE_DATE_FROM_PERIOD',
+ type: 'ADD_EXCLUDED_DATE',
index: 0,
dayTypes: arrDayTypes,
date: "2017-05-01"
@@ -178,13 +215,13 @@ describe('timetable reducer with filled state', () => {
).toEqual(newState)
})
- it('should handle EXCLUDE_DATE_FROM_PERIOD and remove out_day if TT has it', () => {
+ it('should handle REMOVE_EXCLUDED_DATE', () => {
state.time_table_dates = [{date: "2017-05-01", in_out: false}]
- state.current_month[0].excluded_date = true
+ state.current_month[0].excluded_date = false
let newState = Object.assign({}, state, {time_table_dates: []})
expect(
timetableReducer(state, {
- type: 'EXCLUDE_DATE_FROM_PERIOD',
+ type: 'REMOVE_EXCLUDED_DATE',
index: 0,
dayTypes: arrDayTypes,
date: "2017-05-01"
@@ -194,9 +231,10 @@ describe('timetable reducer with filled state', () => {
it('should handle UPDATE_DAY_TYPES and remove out_day that are out of day types', () => {
state.time_table_dates = [{date: "2017-05-01", in_out: false}]
- let newArrDayTypes = arrDayTypes.slice(0)
- newArrDayTypes[1] = false
- let newState = Object.assign({}, state, {time_table_dates: []})
+ let newArrDayTypes = Array.from(arrDayTypes, (dt, i) => {
+ if (i == 1) dt = false
+ return dt
+ })
expect(
timetableReducer(state, {
type: 'UPDATE_DAY_TYPES',
@@ -205,9 +243,19 @@ describe('timetable reducer with filled state', () => {
).toEqual([])
})
+ it('should handle UPDATE_DAY_TYPES and remove in_day that are in day types and in period', () => {
+ state.time_table_dates = [{ date: "2017-05-16", in_out: true }]
+ expect(
+ timetableReducer(state, {
+ type: 'UPDATE_DAY_TYPES',
+ dayTypes: arrDayTypes
+ }).time_table_dates
+ ).toEqual([])
+ })
+
it('should handle VALIDATE_PERIOD_FORM and add period if modalProps index = false', () => {
let newPeriods = state.time_table_periods.concat({"period_start": "2018-05-15", "period_end": "2018-05-24"})
- let newState = Object.assign({}, state, {time_table_periods: newPeriods})
+ let newState = Object.assign({}, state, {time_table_periods: newPeriods, time_table_dates: []})
let modalProps = {
active: false,
begin: {
@@ -236,4 +284,53 @@ describe('timetable reducer with filled state', () => {
})
).toEqual(newState)
})
+
+ it('should handle VALIDATE_PERIOD_FORM and update period if modalProps index != false', () => {
+
+ let begin = new Date(state.time_table_periods[0].period_start)
+ let end = new Date(state.time_table_periods[0].period_end)
+ let newCM = newCurrentMonth.map((d) => {
+ if (new Date (d.date) >= begin && new Date(d.date) <= end) {
+ d.in_periods = false
+ d.excluded_date = false
+ }
+ return d
+ })
+
+ let newPeriods = state.time_table_periods.map( (p,i) => {
+ if (i == 0) {
+ p.period_start = "2018-05-15"
+ p.period_end = "2018-05-24"
+ }
+ return p
+ })
+ let newState = Object.assign({}, state, {time_table_periods: newPeriods})
+
+ let modalProps = {
+ active: false,
+ begin: {
+ day: '15',
+ month: '05',
+ year: '2018'
+ },
+ end: {
+ day: '24',
+ month: '05',
+ year: '2018'
+ },
+ error: '',
+ index: 0
+ }
+ expect(
+ timetableReducer(state, {
+ type: 'VALIDATE_PERIOD_FORM',
+ modalProps: modalProps,
+ timeTablePeriods: state.time_table_periods,
+ metas: {
+ day_types: arrDayTypes
+ },
+ timetableInDates: state.time_table_dates.filter(d => d.in_out == true)
+ })
+ ).toEqual(newState)
+ })
})
diff --git a/spec/lib/model_attribute_spec.rb b/spec/lib/model_attribute_spec.rb
new file mode 100644
index 000000000..cdba87a90
--- /dev/null
+++ b/spec/lib/model_attribute_spec.rb
@@ -0,0 +1,111 @@
+RSpec.describe ModelAttribute do
+ before(:each) do
+ ModelAttribute.instance_variable_set(:@__all__, [])
+ end
+
+ describe ".define" do
+ it "adds a new instance of ModelAttribute to .all" do
+ expect do
+ ModelAttribute.define(:route, :name, :string)
+ end.to change { ModelAttribute.all.length }.by(1)
+
+ model_attr = ModelAttribute.all.last
+
+ expect(model_attr).to be_an_instance_of(ModelAttribute)
+ expect(model_attr.klass).to eq(:route)
+ expect(model_attr.name).to eq(:name)
+ expect(model_attr.data_type).to eq(:string)
+ end
+ end
+
+ describe ".classes" do
+ it "returns the list of classes of ModelAttributes in .all" do
+ ModelAttribute.define(:route, :name, :string)
+ ModelAttribute.define(:journey_pattern, :name, :string)
+ ModelAttribute.define(:time_table, :start_date, :date)
+
+ expect(ModelAttribute.classes).to match_array([
+ 'Route',
+ 'JourneyPattern',
+ 'TimeTable'
+ ])
+ end
+ end
+
+ describe ".from_code" do
+ it "returns a ModelAttribute from a given code" do
+ ModelAttribute.define(:journey_pattern, :name, :string)
+
+ expect(ModelAttribute.from_code('journey_pattern#name')).to eq(
+ ModelAttribute.new(:journey_pattern, :name, :string)
+ )
+ end
+ end
+
+ describe ".group_by_class" do
+ it "returns all ModelAttributes grouped by klass" do
+ ModelAttribute.define(:route, :name, :string)
+ ModelAttribute.define(:route, :published_name, :string)
+ ModelAttribute.define(:journey_pattern, :name, :string)
+ ModelAttribute.define(:vehicle_journey, :number, :integer)
+
+ expect(ModelAttribute.group_by_class).to eq({
+ route: [
+ ModelAttribute.new(:route, :name, :string),
+ ModelAttribute.new(:route, :published_name, :string),
+ ],
+ journey_pattern: [
+ ModelAttribute.new(:journey_pattern, :name, :string),
+ ],
+ vehicle_journey: [
+ ModelAttribute.new(:vehicle_journey, :number, :integer)
+ ]
+ })
+ end
+ end
+
+ describe ".methods_by_class" do
+ it "returns all ModelAttributes for a given class" do
+ ModelAttribute.define(:route, :name, :string)
+ ModelAttribute.define(:route, :published_name, :string)
+ ModelAttribute.define(:route, :direction, :string)
+ ModelAttribute.define(:journey_pattern, :name, :string)
+
+ expect(ModelAttribute.methods_by_class(:route)).to match_array([
+ ModelAttribute.new(:route, :name, :string),
+ ModelAttribute.new(:route, :published_name, :string),
+ ModelAttribute.new(:route, :direction, :string)
+ ])
+ end
+ end
+
+ describe ".methods_by_class_and_type" do
+ it "returns ModelAttributes of a certain class and type" do
+ ModelAttribute.define(:route, :name, :string)
+ ModelAttribute.define(:route, :checked_at, :date)
+ ModelAttribute.define(:journey_pattern, :name, :string)
+ ModelAttribute.define(:journey_pattern, :section_status, :integer)
+
+ expect(ModelAttribute.methods_by_class_and_type(:route, :string)).to match_array([
+ ModelAttribute.new(:route, :name, :string)
+ ])
+ end
+ end
+
+ describe "#code" do
+ it "returns a string representation of the attribute" do
+ model_attr = ModelAttribute.new(:route, :name, :string)
+
+ expect(model_attr.code).to eq('route#name')
+ end
+ end
+
+ describe "#==" do
+ it "returns true when :klass, :name, and :data_type attributes match" do
+ route_name = ModelAttribute.new(:route, :name, :string)
+ other_route_name = ModelAttribute.new(:route, :name, :string)
+
+ expect(route_name == other_route_name).to be true
+ end
+ end
+end
diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
index 4f9d12730..03e6fcb7d 100644
--- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb
+++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb
@@ -51,7 +51,7 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do
)
error_message = I18n.t(
'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
- local_id: at_stop.vehicle_journey.objectid.local_id,
+ short_id: at_stop.vehicle_journey.objectid.short_id,
max: bad_offset
)
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index f9ace08cc..bb8fabb2e 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -10,6 +10,7 @@ describe Referential, :type => :model do
it { should have_many(:metadatas) }
it { should belong_to(:workbench) }
+ it { should belong_to(:referential_suite) }
context ".referential_ids_in_periode" do
it 'should retrieve referential id in periode range' do
diff --git a/spec/models/referential_suite_spec.rb b/spec/models/referential_suite_spec.rb
new file mode 100644
index 000000000..771187b55
--- /dev/null
+++ b/spec/models/referential_suite_spec.rb
@@ -0,0 +1,5 @@
+RSpec.describe ReferentialSuite, type: :model do
+ it { should belong_to(:new).class_name('Referential') }
+ it { should belong_to(:current).class_name('Referential') }
+ it { should have_many(:referentials) }
+end
diff --git a/spec/policies/api_key_policy_spec.rb b/spec/policies/api_key_policy_spec.rb
index f0242978e..3638a05b2 100644
--- a/spec/policies/api_key_policy_spec.rb
+++ b/spec/policies/api_key_policy_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe ApiKeyPolicy do
end
context 'permission present → ' do
it 'allows a user with a different organisation' do
- add_permissions('api_keys.create', for_user: user)
+ add_permissions('api_keys.create', to_user: user)
expect_it.to permit(user_context, record)
end
end
@@ -40,7 +40,7 @@ RSpec.describe ApiKeyPolicy do
context 'permission present → ' do
before do
- add_permissions('api_keys.update', for_user: user)
+ add_permissions('api_keys.update', to_user: user)
end
it 'denies a user with a different organisation' do
diff --git a/spec/policies/import_policy_spec.rb b/spec/policies/import_policy_spec.rb
new file mode 100644
index 000000000..fd9f3172c
--- /dev/null
+++ b/spec/policies/import_policy_spec.rb
@@ -0,0 +1,41 @@
+RSpec.describe ImportPolicy, type: :policy do
+
+ let( :record ){ build_stubbed :import }
+ before { stub_policy_scope(record) }
+
+ #
+ # Non Destructive
+ # ---------------
+
+ context 'Non Destructive actions →' do
+ permissions :index? do
+ it_behaves_like 'always allowed', 'anything', archived: true
+ end
+ permissions :show? do
+ it_behaves_like 'always allowed', 'anything', archived: true
+ end
+ end
+
+
+ #
+ # Destructive
+ # -----------
+
+ context 'Destructive actions →' do
+ permissions :create? do
+ it_behaves_like 'permitted policy', 'imports.create', archived: true
+ end
+ permissions :destroy? do
+ it_behaves_like 'permitted policy', 'imports.destroy', archived: true
+ end
+ permissions :edit? do
+ it_behaves_like 'permitted policy', 'imports.update', archived: true
+ end
+ permissions :new? do
+ it_behaves_like 'permitted policy', 'imports.create', archived: true
+ end
+ permissions :update? do
+ it_behaves_like 'permitted policy', 'imports.update', archived: true
+ end
+ end
+end
diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb
index 69d0eb17b..d00415fc6 100644
--- a/spec/policies/referential_policy_spec.rb
+++ b/spec/policies/referential_policy_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
permissions :create? do
it 'permissions present → allowed' do
- add_permissions('referentials.create', for_user: user)
+ add_permissions('referentials.create', to_user: user)
expect_it.to permit(user_context, record)
end
it 'permissions absent → forbidden' do
@@ -19,7 +19,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
permissions :new? do
it 'permissions present → allowed' do
- add_permissions('referentials.create', for_user: user)
+ add_permissions('referentials.create', to_user: user)
expect_it.to permit(user_context, record)
end
it 'permissions absent → forbidden' do
@@ -53,7 +53,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
context 'permission present →' do
before do
- add_permissions('referentials.update', for_user: user)
+ add_permissions('referentials.update', to_user: user)
end
context 'same organisation →' do
@@ -108,7 +108,7 @@ RSpec.describe ReferentialPolicy, type: :policy do
context 'permission present →' do
before do
- add_permissions('referentials.update', for_user: user)
+ add_permissions('referentials.update', to_user: user)
end
context 'same organisation →' do
diff --git a/spec/support/permissions.rb b/spec/support/permissions.rb
index 467c07a32..13666aca3 100644
--- a/spec/support/permissions.rb
+++ b/spec/support/permissions.rb
@@ -18,6 +18,7 @@ module Support
connection_links
calendars
footnotes
+ imports
journey_patterns
referentials
routes
diff --git a/spec/support/pundit/policies.rb b/spec/support/pundit/policies.rb
index d5bb63243..a3489d9db 100644
--- a/spec/support/pundit/policies.rb
+++ b/spec/support/pundit/policies.rb
@@ -3,18 +3,18 @@ require 'pundit/rspec'
module Support
module Pundit
module Policies
- def add_permissions(*permissions, for_user:)
- for_user.permissions ||= []
- for_user.permissions += permissions.flatten
+ def add_permissions(*permissions, to_user:)
+ to_user.permissions ||= []
+ to_user.permissions += permissions.flatten
end
def create_user_context(user:, referential:)
UserContext.new(user, referential: referential)
end
- def add_permissions(*permissions, for_user:)
- for_user.permissions ||= []
- for_user.permissions += permissions.flatten
+ def remove_permissions(*permissions, from_user:, save: false)
+ from_user.permissions -= permissions.flatten
+ from_user.save! if save
end
end
@@ -30,7 +30,7 @@ module Support
end
def with_user_permission(permission, &blk)
it "with user permission #{permission.inspect}" do
- add_permissions(permission, for_user: user)
+ add_permissions(permission, to_user: user)
blk.()
end
end
@@ -41,7 +41,7 @@ module Support
perms, options = permissions.partition{|x| String === x}
context "with permissions #{perms.inspect}...", *options do
before do
- add_permissions(*permissions, for_user: @user)
+ add_permissions(*permissions, to_user: @user)
end
instance_eval(&blk)
end
@@ -51,6 +51,7 @@ module Support
end
RSpec.configure do | c |
+ c.include Support::Pundit::Policies, type: :controller
c.include Support::Pundit::Policies, type: :policy
c.extend Support::Pundit::PoliciesMacros, type: :policy
c.include Support::Pundit::Policies, type: :feature
diff --git a/spec/support/pundit/shared_examples.rb b/spec/support/pundit/shared_examples.rb
index 63a106759..49c6845da 100644
--- a/spec/support/pundit/shared_examples.rb
+++ b/spec/support/pundit/shared_examples.rb
@@ -18,7 +18,7 @@ RSpec.shared_examples 'always allowed' do
context 'different organisations →' do
before do
- add_permissions(permission, for_user: user)
+ add_permissions(permission, to_user: user)
end
it "allows a user with a different organisation" do
expect_it.to permit(user_context, record)
@@ -51,7 +51,7 @@ RSpec.shared_examples 'always forbidden' do
context 'different organisations →' do
before do
- add_permissions(permission, for_user: user)
+ add_permissions(permission, to_user: user)
end
it "denies a user with a different organisation" do
expect_it.not_to permit(user_context, record)
@@ -80,7 +80,7 @@ RSpec.shared_examples 'permitted policy and same organisation' do
context 'permission present → ' do
before do
- add_permissions(permission, for_user: user)
+ add_permissions(permission, to_user: user)
end
it 'denies a user with a different organisation' do
@@ -113,7 +113,7 @@ RSpec.shared_examples 'permitted policy' do
context 'permission present → ' do
before do
- add_permissions(permission, for_user: user)
+ add_permissions(permission, to_user: user)
end
it 'allows user' do