diff options
| author | Luc Donnet | 2018-03-16 13:46:54 +0100 |
|---|---|---|
| committer | Luc Donnet | 2018-03-23 17:21:56 +0100 |
| commit | 57d63b16da07b9e1ee56b6a75737b6580436e9ed (patch) | |
| tree | 54b6d2412c23f3d4604149c73956d4b58339a90f | |
| parent | 17383fa683459fa08e4925f9793f2d5400291f6e (diff) | |
| download | chouette-core-57d63b16da07b9e1ee56b6a75737b6580436e9ed.tar.bz2 | |
Fix stop_area state for filter and display. Update reflex sync to use confirmed_at. Refs #6141
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 6 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 32 | ||||
| -rw-r--r-- | spec/lib/iev_api/client_spec.rb | 261 |
4 files changed, 20 insertions, 281 deletions
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index c77500132..a71392344 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -222,7 +222,7 @@ class StopAreasController < ChouetteController } scope = Chouette::StopArea.where( - "confirmed_at #{@status[:confirmed] ? "IS NOT NULL" : "IS NULL"} + "confirmed_at #{(@status[:confirmed] || @status[:deactivated]) ? "IS NOT NULL" : "IS NULL"} AND deleted_at #{@status[:deactivated] ? "IS NOT NULL" : "IS NULL"}" ) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 79eb314bc..b49741223 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -383,11 +383,11 @@ module Chouette end def activated? - !!(deleted_at.nil? && confirmed_at) + deleted_at.nil? && confirmed_at end def deactivated? - !!(deleted_at && confirmed_at.nil?) + deleted_at.present? end def activate @@ -396,7 +396,6 @@ module Chouette end def deactivate - self.confirmed_at = nil self.deleted_at = Time.now end @@ -406,7 +405,6 @@ module Chouette end def deactivate! - update_attribute :confirmed_at, nil update_attribute :deleted_at, Time.now end diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 7570e4c49..4eb5bb541 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -51,7 +51,7 @@ module Stif stop_areas = results[:Quay] | results[:StopPlace] time = Benchmark.measure do - stop_areas.each do |entry| + stop_areas.in_batches.each do |entry| next unless is_valid_type_of_place_ref?(method, entry) entry['TypeOfPlaceRef'] = self.stop_area_area_type entry, method self.create_or_update_stop_area entry @@ -151,23 +151,25 @@ module Stif def create_or_update_stop_area entry stop = Chouette::StopArea.find_or_create_by(objectid: entry['id'], stop_area_referential: self.defaut_referential ) - stop.kind = :commercial - stop.deleted_at = nil { - :comment => 'Description', - :name => 'Name', - :area_type => 'TypeOfPlaceRef', - :object_version => 'version', - :zip_code => 'PostalRegion', - :city_name => 'Town', - :stif_type => 'OBJECT_STATUS' + kind: :commercial, + deleted_at: nil, + comment: 'Description', + :name 'Name', + :area_type 'TypeOfPlaceRef', + :object_version 'version', + :zip_code 'PostalRegion', + :city_name 'Town', + :stif_type 'OBJECT_STATUS', + longitude: (entry['gml:pos'][:lng] && entry['gml:pos'][:lng]) ? entry['gml:pos'][:lng] : nil, + latitude: (entry['gml:pos'][:lat] && entry['gml:pos'][:lat]) ? entry['gml:pos'][:lat] : nil }.each do |k, v| stop[k] = entry[v] end - # TODO: use stop.update_attributes instead of the above - if entry['gml:pos'] - stop['longitude'] = entry['gml:pos'][:lng] - stop['latitude'] = entry['gml:pos'][:lat] - end + # if entry['gml:pos'] + # stop['longitude'] = entry['gml:pos'][:lng] + # stop['latitude'] = entry['gml:pos'][:lat] + # end + stop.confirmed_at = Time.now if stop.new_record? if stop.changed? stop.created_at = entry[:created] diff --git a/spec/lib/iev_api/client_spec.rb b/spec/lib/iev_api/client_spec.rb deleted file mode 100644 index f82bf0cae..000000000 --- a/spec/lib/iev_api/client_spec.rb +++ /dev/null @@ -1,261 +0,0 @@ -# require 'spec_helper' - -# describe IevApi::Client do -# describe 'initialization' do -# before do -# @keys = IevApi::Configuration::VALID_OPTIONS_KEYS -# end - -# context "with module configuration" do -# before do -# IevApi.configure do |config| -# @keys.each do |key| -# config.send("#{key}=", key) -# end -# end -# end - -# after do -# IevApi.reset -# end - -# it "should inherit module configuration" do -# api = IevApi::Client.new -# @keys.each do |key| -# expect(api.send(key)).to eq(key) -# end -# end - -# context "with class configuration" do - -# before do -# @configuration = { -# :account => 'test', -# :auth_token => 'token', -# :secure => true, -# :connection_options => {}, -# :adapter => :em_http, -# :user_agent => 'Iev API Tests', -# :middleware => IevApi::Configuration::DEFAULT_MIDDLEWARE -# } -# end - -# context "during initialization" do -# it "should override module configuration" do -# api = IevApi::Client.new(@configuration) -# @keys.each do |key| -# expect(api.send(key)).to eq(@configuration[key]) -# end -# end -# end - -# context "after initilization" do -# it "should override module configuration after initialization" do -# api = IevApi::Client.new -# @configuration.each do |key, value| -# api.send("#{key}=", value) -# end -# @keys.each do |key| -# expect(api.send(key)).to eq(@configuration[key]) -# end -# end -# end -# end -# end - -# # context 'with customized middleware' do -# # let(:logdev) { StringIO.new } -# # # Client#connection is a private method. -# # # Adding logger middleware component with an argument it should receive -# # # when a connection is initialized -# # let(:logger_middleware) { [Faraday::Response::Logger, Logger.new(logdev)] } -# # let(:options) do -# # { -# # :account => 'myapp', :auth_token => 'abcdefg123456', :secure => false, -# # :middleware => IevApi::Configuration::DEFAULT_MIDDLEWARE + [logger_middleware] -# # } -# # end -# # let(:api) { IevApi::Client.new(options) } - -# # # request something to initialize @connection with middleware -# # #before { api.jobs("test") } - -# # it 'splats array to initialize middleware with arguments' do -# # # check that the logger added above did receive the argument -# # expect(logdev.string).to include(api.projects_path) -# # end -# # end -# end - -# describe 'api requests'do -# before(:all) do -# options = { :account => 'myapp', :secure => false } -# IevApi.configure(options) - -# @client = IevApi::Client.new -# end - -# # it "should fail with errors" do -# # expect { -# # @client.notices(1696172) -# # }.to raise_error(IevApi::AirbrakeError, /You are not authorized to see that page/) -# # end - -# # describe '#deploys' do -# # it 'returns an array of deploys' do -# # expect(@client.deploys('12345')).to be_kind_of(Array) -# # end - -# # it 'returns deploy data' do -# # deploys = @client.deploys('12345') -# # first_deploy = deploys.first - -# # expect(first_deploy.rails_env).to eq('production') -# # end - -# # it 'returns empty when no data' do -# # expect(@client.deploys('67890')).to be_kind_of(Array) -# # end -# # end - -# # describe '#projects' do -# # it 'returns an array of projects' do -# # expect(@client.projects).to be_kind_of(Array) -# # end - -# # it 'returns project data' do -# # projects = @client.projects -# # expect(projects.size).to eq(4) -# # expect(projects.first.id).to eq('1') -# # expect(projects.first.name).to eq('Venkman') -# # end -# # end - -# # describe '#update' do -# # it 'should update the status of an error' do -# # error = @client.update(1696170, :group => { :resolved => true}) -# # expect(error.resolved).to be_truthy -# # end -# # end - -# # describe '#errors' do -# # it "should find a page of the 30 most recent errors" do -# # errors = @client.errors -# # ordered = errors.sort_by(&:most_recent_notice_at).reverse -# # expect(ordered).to eq(errors) -# # expect(errors.size).to eq(30) -# # end - -# # it "should paginate errors" do -# # errors = @client.errors(:page => 2) -# # ordered = errors.sort_by(&:most_recent_notice_at).reverse -# # expect(ordered).to eq(errors) -# # expect(errors.size).to eq(2) -# # end - -# # it "should use project_id for error path" do -# # expect(@client).to receive(:request).with(:get, "/projects/123/groups.xml", {}).and_return(double(:group => 111)) -# # @client.errors(:project_id => 123) -# # end -# # end - -# # describe '#error' do -# # it "should find an individual error" do -# # error = @client.error(1696170) -# # expect(error.action).to eq('index') -# # expect(error.id).to eq(1696170) -# # end -# # end - -# # describe '#notice' do -# # it "finds individual notices" do -# # expect(@client.notice(1234, 1696170)).not_to be_nil -# # end - -# # it "finds broken notices" do -# # expect(@client.notice(666, 1696170)).not_to be_nil -# # end -# # end - -# # describe '#notices' do -# # it "finds all error notices" do -# # notices = @client.notices(1696170) -# # expect(notices.size).to eq(42) -# # end - -# # it "finds error notices for a specific page" do -# # notices = @client.notices(1696170, :page => 1) -# # expect(notices.size).to eq(30) -# # expect(notices.first.backtrace).not_to eq(nil) -# # expect(notices.first.id).to eq(1234) -# # end - -# # it "finds all error notices with a page limit" do -# # notices = @client.notices(1696171, :pages => 2) -# # expect(notices.size).to eq(60) -# # end - -# # it "yields batches" do -# # batches = [] -# # notices = @client.notices(1696171, :pages => 2) do |batch| -# # batches << batch -# # end -# # expect(notices.size).to eq(60) -# # expect(batches.map(&:size)).to eq([30,30]) -# # end - -# # it "can return raw results" do -# # notices = @client.notices(1696170, :raw => true) -# # expect(notices.first.backtrace).to eq(nil) -# # expect(notices.first.id).to eq(1234) -# # end -# # end - -# # describe '#connection' do -# # it 'returns a Faraday connection' do -# # expect(@client.send(:connection)).to be_kind_of(Faraday::Connection) -# # end -# # end -# end - -# # describe '#url_for' do -# # before(:all) do -# # options = { :account => 'myapp', :auth_token => 'abcdefg123456', :secure => false } -# # IevApi.configure(options) - -# # @client = IevApi::Client.new -# # end - -# # it 'generates web urls for projects' do -# # expect(@client.url_for(:projects)).to eq('http://myapp.airbrake.io/projects') -# # end - -# # it 'generates web urls for deploys' do -# # expect(@client.url_for(:deploys, '2000')).to eq('http://myapp.airbrake.io/projects/2000/deploys') -# # end - -# # it 'generates web urls for errors' do -# # expect(@client.url_for(:errors)).to eq('http://myapp.airbrake.io/groups') -# # end - -# # it 'generates web urls for errors with project_id' do -# # expect(@client.url_for(:errors, :project_id => 123)).to eq('http://myapp.airbrake.io/projects/123/groups') -# # end - -# # it 'generates web urls for individual errors' do -# # expect(@client.url_for(:error, 1696171)).to eq('http://myapp.airbrake.io/errors/1696171') -# # end - -# # it 'generates web urls for notices' do -# # expect(@client.url_for(:notices, 1696171)).to eq('http://myapp.airbrake.io/groups/1696171/notices') -# # end - -# # it 'generates web urls for individual notices' do -# # expect(@client.url_for(:notice, 123, 1696171)).to eq('http://myapp.airbrake.io/groups/1696171/notices/123') -# # end - -# # it 'raises an exception when passed an unknown endpoint' do -# # expect { @client.url_for(:foo) }.to raise_error(ArgumentError) -# # end -# # end -# end |
