diff options
| author | Luc Donnet | 2018-02-06 11:20:16 +0100 |
|---|---|---|
| committer | GitHub | 2018-02-06 11:20:16 +0100 |
| commit | 7d1c680a97965ae21405cb2fe8564e823d6b01ef (patch) | |
| tree | 91a6051bfee78c9f2ff9b351ee4b5c8815a3a19b | |
| parent | 40bbdede46769b9c2ae3ea38410614286322b5b2 (diff) | |
| parent | a192d4736028b535a1030c0f506597845a3bc4a4 (diff) | |
| download | chouette-core-7d1c680a97965ae21405cb2fe8564e823d6b01ef.tar.bz2 | |
Merge pull request #279 from af83/5835-fix-timetable-creation
5835 Timetables inherit application days from calendars
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/time_tables_controller_spec.rb | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0707b9648..0dcadad1e 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -36,7 +36,6 @@ class TimeTablesController < ChouetteController def create tt_params = time_table_params if tt_params[:calendar_id] && tt_params[:calendar_id] != "" - %i(monday tuesday wednesday thursday friday saturday sunday).map { |d| tt_params[d] = true } calendar = Calendar.find(tt_params[:calendar_id]) tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) end @@ -45,6 +44,7 @@ class TimeTablesController < ChouetteController @time_table = created_from ? created_from.duplicate : Chouette::TimeTable.new(tt_params) if calendar + @time_table.int_day_types = calendar.int_day_types calendar.dates.each_with_index do |date, i| @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i, in_out: true) end diff --git a/spec/controllers/time_tables_controller_spec.rb b/spec/controllers/time_tables_controller_spec.rb new file mode 100644 index 000000000..85f2c10e4 --- /dev/null +++ b/spec/controllers/time_tables_controller_spec.rb @@ -0,0 +1,29 @@ +RSpec.describe TimeTablesController, :type => :controller do + login_user + + describe 'POST create' do + let(:request){ post :create, referential_id: referential.id, time_table: time_table_params } + let(:time_table_params){{comment: "test"}} + + it "should create a timetable" do + expect{request}.to change{ Chouette::TimeTable.count }.by 1 + expect(Chouette::TimeTable.last.comment).to eq "test" + %i(monday tuesday wednesday thursday friday saturday sunday).each do |d| + expect(Chouette::TimeTable.last.send(d)).to be_falsy + end + end + + context "when given a calendar" do + let(:calendar){ create :calendar, int_day_types: Calendar::MONDAY | Calendar::SUNDAY } + let(:time_table_params){{comment: "test", calendar_id: calendar.id}} + it "should create a timetable" do + expect{request}.to change{ Chouette::TimeTable.count }.by 1 + expect(Chouette::TimeTable.last.comment).to eq "test" + expect(Chouette::TimeTable.last.calendar).to eq calendar + %i(monday tuesday wednesday thursday friday saturday sunday).each do |d| + expect(Chouette::TimeTable.last.send(d)).to eq calendar.send(d) + end + end + end + end +end |
