I'm setting all of my rspec tests, they work just fine, but some of them include a call to an API. Therefore, for these tests, I stub the request.
Unfortunately, request looks like this :
stub_request(:get, "https://api.sandbox.mangopay.c['my datas']").
with(:body => "{}",
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby', 'X-Mangopay-Client-User-Agent'=>'{"bindings_version":"3.0.21","lang":"ruby","lang_version":"2.3.0 p0 (2015-12-25)","platform":"x86_64-linux","uname":"Linux wolf-N751JK 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux"}'})
stub_request(:post, "https://api.sandbox.mangopay.com/v2.01/oauth/token").
with(:body => "grant_type=client_credentials",
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Basic a3Jhd2RzYXM6eWtVdEdiUHU5NzJBRjc2cEx0YjBLRHJoQTZrMTBCTDVvY3I2ZFBRalpqS1p1RDBlWm4=', 'User-Agent'=>'Ruby'})
Notice this part:
Linux wolf-N751JK 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
I assume it is linked to my ubunutu version, which means that everytime I update my software, I'll have to change each and every stub. Is there a way to bypass this ?
Have you tried just not specifying the X-Mangopay-Client-User-Agent header?
Related
When I am using 'hicharts-export-server' as local service module in node.js to rendering and exporting images, i got these error message after 7 hours :
Tue Mar 19 2019 13:31:33 GMT+0800 (China Standard Time) [error]
phantom worker 631 error - worker.js resource error - {
"errorCode": 3,
"errorString": "Host cdnjs.cloudflare.com not found",
"id": 2,
"status": null,
"statusText": null,
"url": "https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.13/moment-timezone-with-data-2012-2022.min.js"
}
Tue Mar 19 2019 13:31:33 GMT+0800 (China Standard Time) [error]
phantom worker "Host cdnjs.cloudflare.com not found",
"id": 1,
"status": null,
"statusText": null,
"url": "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"
}
I think the phantom worker was trying download js files from external server but failed, so I want to save these js files to local disk and the phantom worker do know download each time.
How to solve this problem?
Thank a lot !
Since version 2.0.9, in highcharts-export-server you can enable moment.js
by running npm install interactively, or by setting the environment variable HIGHCHARTS_MOMENT to 1.
Related issue: https://github.com/highcharts/node-export-server/issues/119
Never mind please, I found these scripts and changed the url to local file, problem was solved.
sorry for my disturbing.
I am attempting to port REDHAWK 1.9.0 to Fedora 20. I have been (so far as I can tell) successful at coercing everything into compiling. However, I am unable to get a domain to instantiate properly. After selecting a domain and device manager, I receive the message:
Failed to connect to domain: REDHAWK_DEV
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
OmniNames and OmniEvents are running happily, but REDHAWK isn't interfacing properly.
The console provides a little more info:
Jan 08, 2014 6:01:30 PM com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 192.168.118.129; port: 900"
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2200)
at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2221)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:223)
...and so forth
Since the error message concerns port 900, there seems to be some issue with the Java bootstrapping function.
My cfg file is simple:
InitRef = NameService=corbaname::127.0.0.1:2809
InitRef = EventService=corbaloc::127.0.0.1:11169/omniEvents
endPoint = giop:tcp:127.0.0.1:
endPoint = giop:unix:
endPointPublish = all(addr)
supportBootstrapAgent=1
I have tried various permutations of bootstrapAgentHostname and
bootstrapAgentPort in the config file, and have disabled IPv6, but without luck.
Any suggestions on what I might be doing wrong, or what configuration options I may be missing in the configuration file?
I have a ruby script in my rails app in the script directory. How can I access the in_time_zone method in the script?
If you only need that one method, you could just whack require 'active_support/all' at the top of your script.
It's in active_support/core_ext.
> require 'active_support/core_ext'
=> true
> d = DateTime.new(2000)
=> Sat, 01 Jan 2000 00:00:00 +0000
> d.in_time_zone("Alaska")
=> Fri, 31 Dec 1999 15:00:00 AKST -09:00
>
You can create a custom rake task, and then access everything in your application for instance. You can check this great screencast
To start, I am using an old rails version because of Redmine.
I am trying to write a script for updating Redmine's database dump timestamps' to a specific timezone, therefore I need ruby to parse them and change the timezone, assuming rails can handle dst boundaries.
Nevertheless, I found an inconsistency in (or misunderstood) how Time.parse works.
Here's the script I executed on my Rails 2.3.5 raw application:
impulse#ImpulseServer:~/pgtz_converter$ script/console
Loading development environment (Rails 2.3.5)
>> Time.zone
=> #<ActiveSupport::TimeZone:0x7fa94a57b9a8 #tzinfo=nil, #name="UTC", #utc_offset=0>
>> Time.parse('2011-02-19 23:00:00')
=> Sat Feb 19 23:00:00 -0200 2011
>> Time.zone
=> #<ActiveSupport::TimeZone:0x7fa94a57b9a8 #tzinfo=nil, #name="UTC", #utc_offset=0>
>> Time.parse('2011-02-20 00:00:00')
=> Sun Feb 20 00:00:00 -0300 2011
>> Time.zone
=> #<ActiveSupport::TimeZone:0x7fa94a57b9a8 #tzinfo=nil, #name="UTC", #utc_offset=0>
>> Time.parse('2011-02-19 23:00:00')
=> Sat Feb 19 23:00:00 -0300 2011
>> Time.zone
=> #<ActiveSupport::TimeZone:0x7fa94a57b9a8 #tzinfo=nil, #name="UTC", #utc_offset=0>
>> exit
Here's what is going on above:
The server local datetime zone is BRT.
impulse#ImpulseServer:~/pgtz_converter$ date
Fri Apr 8 19:17:34 BRT 2011
First I check Time.zone (which is UTC), then try to parse a DST date.
The output is fine, DST is on (I presume Time.zone = UTC means Ruby checked the server zone configuration and used it).
Then I try another date, in which DST was not active anymore (DST ended on 02/20/2011 00:00 here).
This date is correctly parsed (GMT-3).
Now the problem begins.
I try to parse again the old DST date, and the result is wrong! It wasn't read as a DST date!
I thought perhaps the parsing changed the Time.zone, but as it is pasted it is UTC all the time.
What is causing this ?
Thank you for reading.
Nilo
You might want to change to use the ActiveSupport::TimeWithZone class in rails.
My Ruby on Rails application uses the following controller code to generate a sitemap.xml file:
class SitemapController < ApplicationController
layout nil
def index
headers['Content-Type'] = 'application/xml'
last_post = Post.last
if stale?(:etag => last_post, :last_modified => last_post.updated_at.utc)
respond_to do |format|
format.xml { #posts = Post.sitemap } # sitemap is a named scope
end
end
end
end
My understanding is that the stale? method should ensure a HTTP 304 Not Modified response if the content hasn't changed. However, whenever I test this using curl or a web browser I always get an HTTP 200:
$ curl --head localhost:3000/sitemap.xml
HTTP/1.1 200 OK
Connection: close
Date: Mon, 13 Apr 2009 15:50:00 GMT
Last-Modified: Wed, 08 Apr 2009 16:52:07 GMT
X-Runtime: 100
ETag: "5ff2ed60ddcdecf291e7191e1ad540f6"
Cache-Control: private, max-age=0, must-revalidate
Content-Type: application/xml; charset=utf-8
Content-Length: 29318
Am I using the stale? method correctly? Is it even possible to test this locally?
it is likely that your Rails code is just fine but curl is not sending the If-Modified-Since header when you perform your test. From the curl docs:
TIME CONDITIONS
HTTP allows a client to specify a time
condition for the document it
requests. It is If-Modified-Since or
If-Unmodified-Since. Curl allow you to
specify them with the -z/--time-cond
flag.
For example, you can easily make a
download that only gets performed if
the remote file is newer than a local
copy. It would be made like:
curl -z local.html
http://remote.server.com/remote.html
Or you can download a file only if the
local file is newer than the remote
one. Do this by prepending the date
string with a '-', as in:
curl -z -local.html
http://remote.server.com/remote.html
You can specify a "free text" date as
condition. Tell curl to only download
the file if it was updated since
yesterday:
curl -z yesterday
http://remote.server.com/remote.html
Curl will then accept a wide range of
date formats. You always make the date
check the other way around by
prepending it with a dash '-'.