aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-08-30 22:07:43 +0200
committerLuc Donnet2017-08-30 22:07:43 +0200
commit26c4b71042d258da2fc9ccd67855219b9b012c6b (patch)
tree21b63dbc94f60a955f8a51db2628984e12bd4f1a
parent4d28e063f7071501eef61b59cf8a90730760c523 (diff)
parent637defea87489a4f969766e638d190facd54009a (diff)
downloadchouette-core-26c4b71042d258da2fc9ccd67855219b9b012c6b.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js2
-rw-r--r--app/models/import.rb4
-rw-r--r--app/views/time_table_combinations/_form.html.slim2
-rw-r--r--spec/models/import_spec.rb164
4 files changed, 100 insertions, 72 deletions
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js
index 0d8e54b1e..5157300ba 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/select2s/TimetableSelect2.js
@@ -36,7 +36,7 @@ class BSelect4 extends React.Component{
let newParmas = params.term.split(" ")
return {
q: {
- objectid_end_any: newParmas,
+ objectid_cont_any: newParmas,
comment_cont_any: newParmas,
m: 'or'
}
diff --git a/app/models/import.rb b/app/models/import.rb
index 5f83ed255..9daff0494 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -33,11 +33,11 @@ class Import < ActiveRecord::Base
end
def notify_parent
- parent.child_change(self)
+ parent.child_change
update(notified_parent_at: DateTime.now)
end
- def child_change(child)
+ def child_change
return if self.class.finished_statuses.include?(status)
update_status
diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim
index 581f00457..8e2d77d46 100644
--- a/app/views/time_table_combinations/_form.html.slim
+++ b/app/views/time_table_combinations/_form.html.slim
@@ -7,7 +7,7 @@
abbr title='Champ requis' *
= f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' }
- = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
+ = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_cont_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
= f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''}
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 69c77da91..941e5b386 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -1,4 +1,4 @@
-RSpec.describe Import, :type => :model do
+RSpec.describe Import, type: :model do
it { should belong_to(:referential) }
it { should belong_to(:workbench) }
@@ -48,12 +48,27 @@ RSpec.describe Import, :type => :model do
end
end
- # TODO: Move most of these to #update_status
- describe "#child_change", skip: "THE CODE CHANGED AND THESE SPECS NO LONGER WORK. FIX THEM ASAP!!!~!~!@~" do
+ describe "#child_change" do
+ it "calls #update_status" do
+ allow(workbench_import).to receive(:update)
+
+ expect(workbench_import).to receive(:update_status)
+ workbench_import.child_change
+ end
+
+ it "calls #update_referentials" do
+ allow(workbench_import).to receive(:update)
+
+ expect(workbench_import).to receive(:update_referentials)
+ workbench_import.child_change
+ end
+ end
+
+ describe "#update_status" do
shared_examples(
- "updates :status to failed when child status indicates failure"
+ "updates :status to failed when >=1 child has failing status"
) do |failure_status|
- it "updates :status to failed when child status indicates failure" do
+ it "updates :status to failed when >=1 child has failing status" do
workbench_import = create(:workbench_import)
create(
:netex_import,
@@ -61,102 +76,115 @@ RSpec.describe Import, :type => :model do
status: failure_status
)
- expect(workbench_import).to receive(:update).with(
- current_step: 1,
- status: 'failed'
- )
+ workbench_import.update_status
- workbench_import.child_change
+ expect(workbench_import.status).to eq('failed')
end
end
include_examples(
- "updates :status to failed when child status indicates failure",
+ "updates :status to failed when >=1 child has failing status",
"failed"
)
include_examples(
- "updates :status to failed when child status indicates failure",
+ "updates :status to failed when >=1 child has failing status",
"aborted"
)
include_examples(
- "updates :status to failed when child status indicates failure",
+ "updates :status to failed when >=1 child has failing status",
"canceled"
)
- # TODO: rewrite these for new #update_status
- # it "updates :status to successful when #ready?" do
- # expect(workbench_import).to receive(:update).with(status: 'successful')
- #
- # workbench_import.child_change
- # end
- #
- # it "updates :status to failed when #ready? and child is failed" do
- # build_stubbed(
- # :netex_import,
- # parent: workbench_import,
- # status: :failed
- # )
- #
- # expect(workbench_import).to receive(:update).with(status: 'failed')
- #
- # workbench_import.child_change
- # end
+ it "updates :status to successful when all children are successful" do
+ workbench_import = create(:workbench_import)
+ create_list(
+ :netex_import,
+ 2,
+ parent: workbench_import,
+ status: 'successful'
+ )
+
+ workbench_import.update_status
+
+ expect(workbench_import.status).to eq('successful')
+ end
+
+ it "Updates :status to failed when any child has failed" do
+ workbench_import = create(:workbench_import)
+ [
+ 'failed',
+ 'successful'
+ ].each do |status|
+ create(
+ :netex_import,
+ parent: workbench_import,
+ status: status
+ )
+ end
+
+ workbench_import.update_status
+
+ expect(workbench_import.status).to eq('failed')
+ end
+
+ it "updates :ended_at to now when status is finished" do
+ workbench_import = create(:workbench_import)
+ create(
+ :netex_import,
+ parent: workbench_import,
+ status: 'failed'
+ )
+
+ Timecop.freeze(Time.now) do
+ workbench_import.update_status
+
+ expect(workbench_import.ended_at).to eq(Time.now)
+ end
+ end
+ end
+
+ describe "#update_referentials" do
+ it "doesn't update referentials if parent status isn't finished" do
+ workbench_import = create(:workbench_import, status: 'pending')
+ netex_import = create(:netex_import, parent: workbench_import)
+ netex_import.referential.update(ready: false)
+
+ workbench_import.update_referentials
+ netex_import.referential.reload
+
+ expect(netex_import.referential.ready).to be false
+ end
shared_examples(
- "doesn't update :status if parent import status is finished"
+ "makes child referentials `ready` when status is finished"
) do |finished_status|
- it "doesn't update :status if parent import status is finished" do
- workbench_import = build_stubbed(
- :workbench_import,
- total_steps: 2,
- current_step: 2,
- status: finished_status
- )
- double('Import')
+ it "makes child referentials `ready` when status is finished" do
+ workbench_import = create(:workbench_import, status: finished_status)
+ netex_import = create(:netex_import, parent: workbench_import)
+ netex_import.referential.update(ready: false)
- expect(workbench_import).not_to receive(:update)
+ workbench_import.update_referentials
+ netex_import.referential.reload
- workbench_import.child_change
+ expect(netex_import.referential.ready).to be true
end
end
include_examples(
- "doesn't update :status if parent import status is finished",
+ "makes child referentials `ready` when status is finished",
"successful"
)
include_examples(
- "doesn't update :status if parent import status is finished",
+ "makes child referentials `ready` when status is finished",
"failed"
)
include_examples(
- "doesn't update :status if parent import status is finished",
+ "makes child referentials `ready` when status is finished",
"aborted"
)
include_examples(
- "doesn't update :status if parent import status is finished",
+ "makes child referentials `ready` when status is finished",
"canceled"
)
-
- it "calls #update_status" do
- allow(workbench_import).to receive(:update)
-
- expect(workbench_import).to receive(:update_status)
- workbench_import.child_change
- end
-
- it "calls #update_referential" do
- allow(workbench_import).to receive(:update)
-
- expect(workbench_import).to receive(:update_referential)
- workbench_import.child_change
- end
end
-
- describe "#update_status" do
- it "updates :ended_at to now when status is finished" do
- skip "Redo the `#update_status` code to make it easier to write this."
- end
- end
-
- # TODO: specs for #update_referential
end