mercredi 2 mars 2022

Does rails have async controller?

I am trying to write in a way similar to node.js. I would like to use async libraries like concurrent-ruby. The method DoTaskAsync returns a future and I could chain with a then function. The main thread of the calls the original post method could return quickly without being blocked.

class TasksController < ApplicationController
  def post
    DoTaskAsync
    .then do |res|
      respond_to do |format| # possible?
        format.json { render json: res }
      end
    end
  end
end

mercredi 23 février 2022

Ruby RSpec for checking exception not passing

I have an rspec where I am testing if an exception thrown from method1 is rescued and raised again in method2 (method2 calls method1). But the RSpec seems to fail. I have debugged through the code and can see the exception being raised.


  it 'should check for exceptions raised' do
      allow(TestClass).to receive(:method1) do
        raise ::Test::CustomException.new(1, 'test.csv.gz', StandardError.new('test exception'))
      end
      expect(@test_class.method2).to raise_error(Test::CustomException)
  end


  method2
   tester["key_list"].each do |key|
        begin
        TestClass.method1(key, self.id) do |row|
          #do something
        end
        rescue Test::CustomException => exception
          raise ::Test::CustomException.new(self.id, key, exception)
        end
  end

  method1
     begin
         #do something
     rescue => exc
        raise ::Test::CustomException.new(id, key, exc)
     end
  end

CustomException as the name says is a custom defined exception that takes in 3 parameters

Error:

Failures:

  1. should check for exceptions raised Failure/Error: expect(@test_class.method2).to raise_error

    Test::CustomException: true test_class.rb:146:in `rescue in block method'

vendredi 18 février 2022

LMS Integration (Moodle) in ruby

I want to integrate LMS in our application, as I am new to this. it would be great if some one share the knowledge of LMS architecture.

Likeour customer want to access our content via LMS/LTI how we can proceed and what key features we need to consider and what are the challenges.

how to check if a method is called or not in rspec

as i try to check internally my method was calling or not in rspec but it got the following errors


context "#Meeting_schedule" do
    let(:meeting_schedule) { FactoryGirl.create(:meeting_schedule,:time=>"morning",:schedule_name=>"planned_meet", :schedule_info=>[{ "from"=>"00:00", "to"=>"00:01"}]) }

    it "if the same schedule was created again dont save it again" do 
      schedule.save
      params = {:time=>"morning",:schedule_name=>"planned_meet", :schedule_info=>[{ "from"=>"00:00", "to"=>"00:01"}]}
      meeting_schedule.create_or_update_meeting_schedule(params)
      expect(meeting_schedule).to receive(:updating_the_user)
    end
  end


i got the following error

Failure/Error: expect(meeting_schedule.create_or_update_meeting_schedule(params)).to receive(:updating_the_user)
       (#<Meeting_schedule:0x0055dbaf0da710>).updating_the_user(*(any args))
           expected: 1 time with any arguments
           received: 0 times with any arguments
     # ./spec/models/meeting_schedule_spec.rb:122:in `block (4 levels) 

so what was wrong in my code?

my method

def create_or_update_meeting_schedule(params)
   self.attributes = params
   if self.changed and self.save
     updating_the_user
   end
   self
end

can anyone help me out

jeudi 17 février 2022

SSL_connect returned=1 errno=0 state=error: certificate verify failed in Mac

I have a rails app integrated with a third party web service. It has been working perfectly since the initial development for years. For some unexpected reason, suddenly it has stopped working. I would say we haven´t changed anything in our code. The only thing that it can be related is the fact that our SSL certificate expired and we renewed it.

The fact is that I´m getting this error when calling the web service request:

E, [2022-02-17T19:53:25.385435 #32501] ERROR -- : SSL_connect returned=1 errno=0 state=error: certificate verify failed
E, [2022-02-17T19:53:25.385876 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/httpi-2.4.4/lib/httpi/adapter/httpclient.rb:28:in `rescue in request'
E, [2022-02-17T19:53:25.386103 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/httpi-2.4.4/lib/httpi/adapter/httpclient.rb:24:in `request'
E, [2022-02-17T19:53:25.386358 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/httpi-2.4.4/lib/httpi.rb:161:in `request'
E, [2022-02-17T19:53:25.386658 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/httpi-2.4.4/lib/httpi.rb:127:in `get'
E, [2022-02-17T19:53:25.386909 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/resolver.rb:43:in `load_from_remote'
E, [2022-02-17T19:53:25.387150 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/resolver.rb:33:in `resolve'
E, [2022-02-17T19:53:25.387349 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/document.rb:142:in `xml'
E, [2022-02-17T19:53:25.387606 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/document.rb:160:in `parse'
E, [2022-02-17T19:53:25.387887 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/document.rb:147:in `parser'
E, [2022-02-17T19:53:25.388162 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/wasabi-3.5.0/lib/wasabi/document.rb:64:in `soap_actions'
E, [2022-02-17T19:53:25.388432 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/savon-2.12.0/lib/savon/operation.rb:22:in `ensure_exists!'
E, [2022-02-17T19:53:25.388696 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/savon-2.12.0/lib/savon/operation.rb:15:in `create'
E, [2022-02-17T19:53:25.388955 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/savon-2.12.0/lib/savon/client.rb:32:in `operation'
E, [2022-02-17T19:53:25.389214 #32501] ERROR -- : /Users/Rober/.rvm/gems/ruby-2.4.9/gems/savon-2.12.0/lib/savon/client.rb:36:in `call'

I´m not skilled at all with certificates. So, I found this post: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed and basically I´m trying almost everything that I see, but nothing is working. I have the issue in development on Mac running ruby 2.4.9p362 (2019-10-02 revision 67824) [x86_64-darwin19] and Rails 5.2.4 and also in production in Ubuntu. But, I will try to fix it in development first.

dimanche 13 février 2022

rails active storage file uploading

my files were uploading fine and suddenly i am encountering this issue

Errno::EISDIR (Is a directory @ rb_sysopen - /home/dev/Desktop/project/storage/):

I have no idea what is happening

mercredi 9 février 2022

split a row or column or cell in ruby spreadsheet gems

How do I split a row or column or cell in ruby spreadsheet gems? sheet.split_cells(start_row, start_col, end_row, end_col)

I tried this getting undefined method error