How to use and method of Synchronizer Package

Best Capybara code snippet using Synchronizer.and

synchronizers_spec.rb

Source:synchronizers_spec.rb Github

copy

Full Screen

...13 }14 end15 describe "GET /me/synchronizers" do16 before do17 syncer = TWEInvoiceSyncer.new(user: user, uid: SecureRandom.uuid, name: 'My Syncer', passcode_1: '0987654321', passcode_2: 'passcode_2')18 syncer.save!19 end20 it "returns a list of synchronizers" do21 get '/me/synchronizers', authorization_header22 expect(response).to be_success23 expect_status(200)24 expect_json_types 'synchronizers.*', user_id: :integer,25 uid: :string,26 type: :string,27 enabled: :boolean,28 schedule: :string,29 name: :string,30 status: :string,31 email_endpoint: :string_or_null32 end33 end34 describe "PUT /me/synchronizers/{synchronizer_uid}" do35 let(:synchronizer_uid) { SecureRandom.uuid }36 subject(:request) do37 put "/me/synchronizers/#{synchronizer_uid}", authorization_header.merge(38 params: {39 synchronizer: {40 name: 'My Synchronizer',41 type: 'tw_einvoice',42 passcode_1: '0987654321',43 passcode_2: 'abc123'44 }45 }46 )47 end48 context "no synchronizer with the matching uid exists" do49 it "creates a new synchronizer and returns its data with 201" do50 request51 expect_status(201)52 new_synchronizer = Synchronizer.last53 expect(new_synchronizer.class).to eq(TWEInvoiceSyncer)54 expect(new_synchronizer.user).to eq(user)55 expect(new_synchronizer.name).to eq('My Synchronizer')56 expect_json_types 'synchronizer', user_id: :integer,57 uid: :string,58 type: :string,59 enabled: :boolean,60 schedule: :string,61 name: :string,62 status: :string63 end64 end65 context "a synchronizer with the matching uid exists" do66 before do67 syncer = TWEInvoiceSyncer.new(user: user, uid: synchronizer_uid, name: 'My Old Syncer', passcode_1: '0900000000', passcode_2: 'pass')68 syncer.save!69 end70 it "replaces the synchronizer with the given attrs and returns the new data with 200" do71 request72 expect_status(200)73 synchronizer = Synchronizer.last74 expect(synchronizer.class).to eq(TWEInvoiceSyncer)75 expect(synchronizer.user).to eq(user)76 expect(synchronizer.name).to eq('My Synchronizer')77 expect(synchronizer.passcode_1).to eq('0987654321')78 expect(synchronizer.passcode_2).to eq('abc123')79 expect_json_types 'synchronizer', user_id: :integer,80 uid: :string,81 type: :string,82 enabled: :boolean,83 schedule: :string,84 name: :string,85 status: :string86 end87 end88 context "bad request with a invalid type" do89 subject(:request) do90 put "/me/synchronizers/#{synchronizer_uid}", authorization_header.merge(91 params: {92 synchronizer: {93 name: 'My Synchronizer',94 type: 'invalid_invalid_invalid', # invalid95 passcode_1: '0987654321',96 passcode_2: 'abc123'97 }98 }99 )100 end101 it "returns an error with code 'bad_attributes' and status 400" do102 request103 expect_status(400)104 expect_json_types 'error', status: :integer,105 code: :string,106 message: :string107 expect(json['error']['code']).to eq('bad_attributes')108 end109 end110 context "bad request with missing the type param" do111 subject(:request) do112 put "/me/synchronizers/#{synchronizer_uid}", authorization_header.merge(113 params: {114 synchronizer: {115 name: 'My Synchronizer',116 # type: is missing!117 passcode_1: 'aaaaaa',118 passcode_2: 'abc123'119 }120 }121 )122 end123 it "returns an error with code 'bad_attributes' and status 400" do124 request125 expect_status(400)126 expect_json_types 'error', status: :integer,127 code: :string,128 message: :string129 expect(json['error']['code']).to eq('bad_attributes')130 end131 end132 context "bad request with invalid passcodes" do133 subject(:request) do134 put "/me/synchronizers/#{synchronizer_uid}", authorization_header.merge(135 params: {136 synchronizer: {137 name: 'My Synchronizer',138 type: 'tw_einvoice',139 passcode_1: 'aaaaaa', # invalid140 passcode_2: 'abc123'141 }142 }143 )144 end145 it "returns an error with code 'bad_attributes' and status 400" do146 request147 expect_status(400)148 expect_json_types 'error', status: :integer,149 code: :string,150 message: :string151 expect(json['error']['code']).to eq('bad_attributes')152 end153 end154 end155 describe "PATCH /me/synchronizers/{synchronizer_uid}" do156 let(:synchronizer_uid) { SecureRandom.uuid }157 let!(:syncer) do158 syncer = TWEInvoiceSyncer.new(user: user, uid: synchronizer_uid, name: 'My Syncer', passcode_1: '0987654321', passcode_2: 'passcode_2')159 syncer.save!160 syncer161 end162 subject(:request) do163 patch "/me/synchronizers/#{synchronizer_uid}", authorization_header.merge(164 params: {165 synchronizer: {166 name: 'My Awesone Syncer',167 schedule: 'high_frequency',168 type: 'another_type' # unpermitted attribute169 }170 }171 )172 end173 it "updates the existing syncer with the given attributes and returns the new data" do174 request175 syncer.reload176 expect(syncer.name).to eq('My Awesone Syncer')177 expect(syncer.schedule).to eq('high_frequency')178 expect(json['synchronizer']['name']).to eq('My Awesone Syncer')179 expect(json['synchronizer']['schedule']).to eq('high_frequency')180 end181 it "ignores any unpermitted attribute and returns the new data" do182 request183 syncer.reload184 expect(syncer.type).to eq('tw_einvoice')185 expect(json['synchronizer']['type']).to eq('tw_einvoice')186 end187 context "a synchronizer with the specified uid doesn't exists" do188 subject(:request) do189 patch "/me/synchronizers/not_exixts", authorization_header.merge(190 params: {191 synchronizer: {192 name: 'My Awesone Syncer',193 type: 'another_type' # unpermitted attribute194 }195 }196 )197 end198 it "returns an error with code 'not_found' and status 404" do199 request200 expect_status(404)201 expect_json_types 'error', status: :integer,202 code: :string,203 message: :string204 expect(json['error']['code']).to eq('not_found')205 end206 end207 end208 describe "POST /me/synchronizers/{synchronizer_uid}/_perform_sync" do209 before { allow(SynchronizerRunCollectJob).to receive(:perform_later) }210 let(:synchronizer) { create(:synchronizer, user: user) }211 subject(:request) do212 post "/me/synchronizers/#{synchronizer.uid}/_perform_sync", authorization_header213 end214 it "do perform sync and returns 202" do215 request216 expect(response).to be_success217 expect(response.status).to eq(202)218 expect(json).to have_key('synchronizer')219 end220 context "the syncer is not in a performable status" do221 before do222 synchronizer.perform_sync223 end224 it "returns a error with status 400" do225 request226 expect(response).not_to be_success227 expect(response.status).to eq(400)228 expect(json).to have_key('error')...

Full Screen

Full Screen

synchronizer_spec.rb

Source:synchronizer_spec.rb Github

copy

Full Screen

...13 before :each do14 mock_post_to_tickets @project, @remote_ticket.to_xml, @ticket.remote_id15 @ticket.remote_id = nil16 end17 it "instantiates and saves a new remote ticket" do18 @lighthouse.should_receive(:from_local).with(@ticket).and_return @remote_ticket19 @remote_ticket.should_receive(:save)20 @synchronizer.push! @ticket21 end22 it "updates the ticket's remote_id from the new remote ticket" do23 @ticket.should_receive(:update_attributes).with :remote_id => @remote_ticket.id24 @synchronizer.push! @ticket25 end26 end27 describe "with a remote_id" do28 before :each do29 @lighthouse.stub!(:ticket).and_return @remote_ticket30 @remote_ticket.stub!(:update_attributes!)31 mock_get_to_ticket @project, @ticket.remote_id, @remote_ticket.to_xml32 end33 it "fetches the remote ticket" do34 @lighthouse.should_receive(:ticket).with(@ticket.remote_id).and_return @remote_ticket35 @synchronizer.push! @ticket36 end37 it "updates its attributes to the remote ticket" do38 @remote_ticket.should_receive(:update_attributes!).with @ticket.attributes39 @synchronizer.push! @ticket40 end41 end42end43describe Synchronizer, '#push! given a release' do44 include HttpMockHelper45 before :each do46 @project = Factory :scrumtious47 @release = Factory :release_00148 @synchronizer = @project.synchronizer49 @lighthouse = @synchronizer.send :lighthouse50 @remote_project = @lighthouse.from_local @project51 @remote_milestone = @lighthouse.from_local @release52 end53 describe "with no remote_id" do54 before :each do55 @release.remote_id = nil56 mock_post_to_milestones @project, @remote_milestone.to_xml, @release.remote_id57 end58 it "instantiates and saves a new remote milestone" do59 @lighthouse.should_receive(:from_local).with(@release).and_return @remote_milestone60 @remote_milestone.should_receive(:save)61 @synchronizer.push! @release62 end63 it "updates the release's remote_id from the new remote milestone" do64 @release.should_receive(:update_attributes).with :remote_id => @remote_milestone.id65 @synchronizer.push! @release66 end67 end68 describe "with a remote_id" do69 before :each do70 @lighthouse.stub!(:milestone).and_return @remote_milestone71 @remote_milestone.stub!(:update_attributes!)72 mock_get_to_milestone @project, @release.remote_id, @remote_milestone.to_xml73 end74 it "fetches the remote milestone" do75 @lighthouse.should_receive(:milestone).with(@release.remote_id).and_return @remote_milestone76 @synchronizer.push! @release77 end78 it "updates its attributes to the remote milestone" do79 @remote_milestone.should_receive(:update_attributes!).with @release.attributes80 @synchronizer.push! @release81 end82 end83end84describe Synchronizer, '#push! given a sprint' do85 include HttpMockHelper86 before :each do87 @project = Factory :scrumtious88 @sprint = Factory :sprint_189 @synchronizer = @project.synchronizer90 @lighthouse = @synchronizer.send :lighthouse91 @remote_project = @lighthouse.from_local @project92 @remote_milestone = @lighthouse.from_local @sprint93 end94 describe "with no remote_id" do95 before :each do96 mock_post_to_milestones @project, @remote_milestone.to_xml, 197 @sprint.remote_id = nil98 end99 it "instantiates and saves a new remote milestone" do100 @lighthouse.should_receive(:from_local).with(@sprint).and_return @remote_milestone101 @remote_milestone.should_receive(:save)102 @synchronizer.push! @sprint103 end104 it "updates the sprint's remote_id from the new remote milestone" do105 @sprint.should_receive(:update_attributes).with :remote_id => @remote_milestone.id106 @synchronizer.push! @sprint107 end108 end109 describe "with a remote_id" do110 before :each do111 @lighthouse.stub!(:milestone).and_return @remote_milestone112 @remote_milestone.stub!(:update_attributes!)113 @remote_instance = RemoteInstance.create! :remote_id => 1, :project => @project, :local => @sprint114 mock_get_to_milestone @project, @remote_instance.remote_id, @remote_milestone.to_xml115 end116 it "fetches the remote milestone" do117 @lighthouse.should_receive(:milestone).with(@remote_instance.remote_id).and_return @remote_milestone118 @synchronizer.push! @sprint119 end120 it "updates its attributes to the remote milestone" do121 @remote_milestone.should_receive(:update_attributes!).with @sprint.attributes122 @synchronizer.push! @sprint123 end124 end125end126describe Synchronizer, '#pull_milestones!' do127 include HttpMockHelper128 before :each do129 @project = Factory :scrumtious130 @synchronizer = @project.synchronizer131 @remote_milestone = Lighthouse::Milestone.new :id => 1, :title => 'Sprint #1', :due_on => Time.parse('2008-10-10')132 @sprint = Sprint.new133 Sprint.stub!(:find_or_initialize_for).and_return @sprint134 @synchronizer.send(:lighthouse).stub!(:milestones).and_return [@remote_milestone]135 @synchronizer.stub!(:update_local_remote_instance)136 end137 it "updates local milestones from remote milestones" do138 @synchronizer.should_receive(:update_local).with(@sprint, @remote_milestone)139 @synchronizer.pull_milestones!140 end141 it "updates local remote_instances from a remote milestone if it is a sprint" do142 @synchronizer.should_receive(:update_local_remote_instance).with @sprint, @remote_milestone143 @synchronizer.pull_milestones!144 end145end146describe Synchronizer, '#pull_users!' do147 include HttpMockHelper148 before :each do149 @synchronizer = Factory(:scrumtious).synchronizer150 @remote_user = Lighthouse::User.new :id => 1, :name => 'John Doe'151 @synchronizer.send(:lighthouse).stub!(:users).and_return [@remote_user]152 @user = mock('user')153 User.stub!(:find_or_initialize_by_remote_id).and_return @user154 end155 it "updates local users from remote users" do156 @synchronizer.should_receive(:update_local).with @user, @remote_user157 @synchronizer.pull_users!158 end159end160describe Synchronizer, "#update_local (given a User)" do161 before :each do162 @synchronizer = Factory(:scrumtious).synchronizer163 @remote_user = Lighthouse::User.new :id => 1, :name => 'John Doe'164 @local_attributes = {:remote_id => 1, :name => 'John Doe'}165 @remote_user.stub!(:attributes_for_local).and_return @local_attributes166 @user = mock('user')167 end168 it "updates the user with mapped attributes from remote user" do169 @user.should_receive(:update_attributes!).with @local_attributes170 @synchronizer.send(:update_local, @user, @remote_user)171 end172end173describe Synchronizer, "#update_local_remote_instance (given a Sprint)" do174 before :each do175 @project = Factory :scrumtious176 @synchronizer = @project.synchronizer177 @remote_milestone = Lighthouse::Milestone.new :id => 1, :title => 'Sprint #1', :due_on => Time.parse('2008-10-10')178 @sprint = Sprint.new179 end180 it "creates a new remote_instance for the sprint when it does not exist" do181 @sprint.stub!(:remote_instance).and_return nil182 attributes = {:local => @sprint, :project => @project, :remote_id => @remote_milestone.id}183 @sprint.remote_instances.should_receive(:create!).with attributes184 @synchronizer.send(:update_local_remote_instance, @sprint, @remote_milestone)185 end186 it "does not create a new remote_instance for the sprint when it already exists" do187 @sprint.stub!(:remote_instance).and_return mock('remote_instance')188 @sprint.remote_instances.should_not_receive :create!189 @synchronizer.send(:update_local_remote_instance, @sprint, @remote_milestone)190 end191end...

Full Screen

Full Screen

tariff_synchronizer_spec.rb

Source:tariff_synchronizer_spec.rb Github

copy

Full Screen

...10 end11 describe ".download" do12 context "sync variables are set" do13 before do14 allow(TariffSynchronizer).to receive(:sync_variables_set?).and_return(true)15 end16 it "invokes update downloading/syncing on all update types" do17 expect(TariffSynchronizer::TaricUpdate).to receive(:sync).and_return(true)18 expect(TariffSynchronizer::ChiefUpdate).to receive(:sync).and_return(true)19 TariffSynchronizer.download20 end21 it "logs an info event" do22 allow(TariffSynchronizer::TaricUpdate).to receive(:sync).and_return(true)23 allow(TariffSynchronizer::ChiefUpdate).to receive(:sync).and_return(true)24 tariff_synchronizer_logger_listener25 TariffSynchronizer.download26 expect(@logger.logged(:info).size).to eq 127 expect(@logger.logged(:info).last).to match /Finished downloading updates/28 end29 end30 context "sync variables are not set" do31 it "does not start sync process" do32 allow(TariffSynchronizer).to receive(:sync_variables_set?).and_return(false)33 expect(TariffSynchronizer::TaricUpdate).not_to receive(:sync)34 expect(TariffSynchronizer::ChiefUpdate).not_to receive(:sync)35 TariffSynchronizer.download36 end37 it "logs an error event" do38 tariff_synchronizer_logger_listener39 allow(TariffSynchronizer).to receive(:sync_variables_set?).and_return(false)40 TariffSynchronizer.download41 expect(@logger.logged(:error).size).to eq 142 expect(@logger.logged(:error).last).to match /Missing: Tariff sync enviroment variables/43 end44 end45 context "when a download exception" do46 before do47 expect(TariffSynchronizer).to receive(:sync_variables_set?).and_return(true)48 allow_any_instance_of(Curl::Easy).to receive(:perform)49 .and_raise(Curl::Err::HostResolutionError)50 end51 it "raises original exception ending the process and logs an error event" do52 tariff_synchronizer_logger_listener53 expect { TariffSynchronizer.download }.to raise_error Curl::Err::HostResolutionError54 expect(@logger.logged(:error).size).to eq 155 expect(@logger.logged(:error).last).to match /Download failed/56 end57 it "sends an email with the exception error" do58 ActionMailer::Base.deliveries.clear59 expect { TariffSynchronizer.download }.to raise_error(Curl::Err::HostResolutionError)60 expect(ActionMailer::Base.deliveries).not_to be_empty61 expect(ActionMailer::Base.deliveries.last.encoded).to match /Backtrace/62 expect(ActionMailer::Base.deliveries.last.encoded).to match /Curl::Err::HostResolutionError/63 end64 end65 end66 describe ".apply" do67 let(:update_1) { instance_double("TariffSynchronizer::TaricUpdate", issue_date: Date.yesterday, filename: Date.yesterday) }68 let(:update_2) { instance_double("TariffSynchronizer::TaricUpdate", issue_date: Date.today, filename: Date.today) }69 context "success scenario" do70 before do71 allow(TariffSynchronizer).to receive(:date_range_since_last_pending_update).and_return([Date.yesterday, Date.today])72 expect(TariffSynchronizer::TaricUpdate).to receive(:pending_at).with(update_1.issue_date).and_return([update_1])73 expect(TariffSynchronizer::TaricUpdate).to receive(:pending_at).with(update_2.issue_date).and_return([update_2])74 end75 it "all pending updates get applied" do76 expect(TariffSynchronizer::BaseUpdateImporter).to receive(:perform).with(update_1)77 expect(TariffSynchronizer::BaseUpdateImporter).to receive(:perform).with(update_2)78 TariffSynchronizer.apply79 end80 it "logs the info event and send email" do81 allow(TariffSynchronizer::BaseUpdateImporter).to receive(:perform).with(update_1).and_return(true)82 allow(TariffSynchronizer::BaseUpdateImporter).to receive(:perform).with(update_2).and_return(true)83 tariff_synchronizer_logger_listener84 TariffSynchronizer.apply85 expect(@logger.logged(:info).size).to eq(1)86 expect(@logger.logged(:info).last).to include("Finished applying updates")87 expect(ActionMailer::Base.deliveries).not_to be_empty88 expect(ActionMailer::Base.deliveries.last.subject).to include("Tariff updates applied")89 expect(ActionMailer::Base.deliveries.last.encoded).to include("No conformance errors found.")90 end91 end92 context "failure scenario" do93 before do94 allow(TariffSynchronizer).to receive(:date_range_since_last_pending_update).and_return([Date.yesterday, Date.today])95 allow(TariffSynchronizer::TaricUpdate).to receive(:pending_at).with(update_1.issue_date).and_return([update_1])96 allow(TariffSynchronizer::BaseUpdateImporter).to receive(:perform).with(update_1).and_raise(Sequel::Rollback)97 end98 it "after an error next record is not processed" do99 expect { TariffSynchronizer.apply }.to raise_error(Sequel::Rollback)100 expect(TariffSynchronizer::BaseUpdateImporter).not_to receive(:perform).with(update_2)101 end102 end103 context "with failed updates present" do104 before { create :taric_update, :failed }105 it "does not apply pending updates" do106 expect(TariffSynchronizer::TaricUpdate).not_to receive(:pending_at)107 expect(TariffSynchronizer::ChiefUpdate).not_to receive(:pending_at)108 expect { TariffSynchronizer.apply }.to raise_error(TariffSynchronizer::FailedUpdatesError)109 end110 it "logs the error event" do...

Full Screen

Full Screen

and

Using AI Code Generation

copy

Full Screen

1 @cv.wait(@mutex) while @count < 22 @cv.wait(@mutex) while @count < 23 @cv.wait(@mutex) while @count < 24 @cv.wait(@mutex) while @count < 2

Full Screen

Full Screen

and

Using AI Code Generation

copy

Full Screen

1 def synchronize(&block)2 @mutex.synchronize(&block)3 def synchronize(&block)4 @mutex.synchronize(&block)5 def synchronize(&block)6 @mutex.synchronize(&block)7 def synchronize(&block)8 @mutex.synchronize(&block)9 def synchronize(&block)10 @mutex.synchronize(&block)11 def synchronize(&block)12 @mutex.synchronize(&block)13 def synchronize(&block)14 @mutex.synchronize(&block)15 def synchronize(&block)16 @mutex.synchronize(&block)

Full Screen

Full Screen

and

Using AI Code Generation

copy

Full Screen

1 def sync(&block)2 @cv.wait(@mutex) until @counter == 23 @cv.wait(@mutex) while @count < 24 @cv.wait(@mutex) while @count < 25 @cv.wait(@mutex) while @count < 26 @cv.wait(@mutex) while @count < 2

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Capybara automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful