Here are my gem list,
mongo (1.8.2)
mongoid (3.0.17)
mongoid-grid_fs (1.7.0)
carrierwave (0.8.0)
carrierwave-mongoid (0.4.0)
I have tried to generate an upload image but it dont work, the carrierwave.rb its looks like this:
require 'carrierwave/mongoid'
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid::Config.sessions[:default]
config.grid_fs_port = 27017
config.grid_fs_host = '127.0.0.1'
config.storage = :grid_fs
end
but puts an error:
/config/initializers/carrierwave.rb:3:in `block in <top (required)>': undefined method `grid_fs_database=' for CarrierWave::Uploader::Base:Class (NoMethodError)
.....
there is a solution for that?
thanks
I took a quick look at the source for carrierwave-mongoid and it appears that the configuration options you specified (grid_fs_database, grid_fs_port, and grid_fs_host) are not valid options - hence your error.
My understanding is that carrierwave-mongoid derives its mongoDB configuration from the Mongoid configuration, so there's no need to specify this again. You configuration should look something like this:
require 'carrierwave/mongoid'
CarrierWave.configure do |config|
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads" # or whatever you'd like the HTTP path to be
end
Related
I am using selenoid for remote browser testing in ruby.
In that I am using 'selenium-webdriver', 'capybara', 'rspec' for automation. And I am using attach_file method for uploading file to browser
I want to upload file on Firefox and Chrome browser but it raises error on both;
In chrome
Selenium::WebDriver::Error::UnknownCommandError: unknown command: unknown command: session/***8d32e045e3***/se/file
In firefox
unexpected token at 'HTTP method not allowed'
So After searching I found the solution for chrome which is to set w3c option false in caps['goog:chromeOptions'] > caps['goog:chromeOptions'] = {w3c: false}
So now chrome is using OSS bridge for handshaking but I don't know how to do it in Firefox. Similar solution is not available for Firefox.
My browser capabilities are following:
if ENV['BROWSER'] == 'firefox'
caps = Selenium::WebDriver::Remote::Capabilities.new
caps['browserName'] = 'firefox'
# caps['moz:firefoxOptions'] = {w3c: false} ## It is not working
else
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browserName"] = "chrome"
caps["version"] = "81.0"
caps['goog:chromeOptions'] = {w3c: false}
end
caps["enableVNC"] = true
caps["screenResolution"] = "1280x800"
caps['sessionTimeout'] = '15m'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :remote,
:desired_capabilities => caps,
:url => ENV["REMOTE_URL"] || "http://*.*.*.*:4444/wd/hub"
)
end
Capybara.configure do |config|
config.default_driver = :selenium
end
I have found the problem. There is bug in selenium server which run on java so I have to change my selenium-webdriver gem version 3.142.7 and monkey-patch.
You can find more information here about the bug and resolution.
For now I have to change my gem and monkey patch the selenium-webdriver-3.142.7\lib\selenium\webdriver\remote\w3c\commands.rb file. check for below line which is on line no 150.
upload_file: [:post, 'session/:session_id/se/file']
and update it to
upload_file: [:post, 'session/:session_id/file']
i had a similar issue with rails 7. the issue is connected with the w3c standard. the core problem is that the webdriver for chrome uses a non-w3c standard url for handling file uploads. when uploading a file, the webdriver uses the /se/file url path to upload. this path is only supported by the selenium server. subsequently, the docker image provided by selenium works fine. yet, if we use chromedriver, the upload fails. more info.
we can solve this, by forcing the webdriver to use the standard-compliant url by overriding the :upload_file key in Selenium::WebDriver::Remote::Bridge::COMMANDS. since, the initialization of this the COMMANDS constant does not happen when the module is loaded, we can override the attach_file method to make sure the constant is set correctly. here the hacky code:
module Capybara::Node::Actions
alias_method :original_attach_file, :attach_file
def attach_file(*args, **kwargs)
implement_hacky_fix_for_file_uploads_with_chromedriver
original_attach_file(*args, **kwargs)
end
def implement_hacky_fix_for_file_uploads_with_chromedriver
return if #hacky_fix_implemented
original_verbose, $VERBOSE = $VERBOSE, nil # ignore warnings
cmds = Selenium::WebDriver::Remote::Bridge::COMMANDS.dup
cmds[:upload_file] = [:post, "session/:session_id/file"]
Selenium::WebDriver::Remote::Bridge.const_set(:COMMANDS, cmds)
$VERBOSE = original_verbose
#hacky_fix_implemented = true
end
end
In Firefox images we support /session/<id>/file API by adding Selenoid binary which emulates this API instead of Geckodriver (which does not implement it).
I'm using a ruby/cucumber/capybara framework with versions:
capybara (2.10.1)
selenium-webdriver (3.0.0)
ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32]
and I'm trying to register a new driver with some settings passed in the profile to capybara. My code looks like this:
Capybara.register_driver :debug do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
and I've tried as well with:
Capybara::Selenium::Driver.new(app, :profile => profile)
Then I just use the following to select that driver:
Capybara.default_driver = :debug
but in both cases, when I try to run any test, I get the following error:
ArgumentError: unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile:0x000000068ca798 #model=nil, #native_events=true, #secure_ssl=false, #untrusted_issuer=true, #load_no_focus_lib=false, #additional_prefs={}, #extensions={}>}
Any idea what the problem could be? and how to ammend it?
Firefox Profiles are not yet supported in Ruby bindings for geckodriver, which is needed for Firefox 48+. Watch this issue for (hopefully very soon) resolution: https://github.com/SeleniumHQ/selenium/issues/2933
I have an angularJs app that sends a base64 encoded image (or file) to my rails4 server api that uses paperclip to store attachments. Everything works fine until the content_type_validation paperclip does.
For some reason, paperclip determines the content-type's been spoofed and get the following error message:
[paperclip] Content Type Spoof: Filename 1413325092.jpg (["image/jpeg"]), content type discovered from file command: application/octet-stream; charset=binary. See documentation to allow this combination.
I create the paperclip attachment with the following code:
def self.create_from_base64(base64_string)
decoded_data = Base64.decode64(base64_string)
# create 'file' understandable by Paperclip
data = StringIO.new(decoded_data)
data.class_eval do
attr_accessor :content_type, :original_filename
end
# set file properties
data.content_type = 'application/octet-stream'
data.original_filename = "#{Time.now.to_i}.jpg"
end
I've tried different things but for some reason even when I set data.content_type = 'application/octet-stream', the error is exactly the same, and paperclip it's been spoofed.
Any ideas?
Thanks,
EDIT:
I have the following validation:
validates_attachment_content_type :file, :content_type => [/png\Z/, /jpe?g\Z/, /application\/octet-stream*/]
So I've tried configuring AppEngine logging according to this guide, ensuring I've configured the logging.properties file to be used in web.xml. I've configured logging.properties the following way:
.level = WARNING
nilsnett.chinese.backend.level = INFO
The package name of my logging wrapper is nilsnett.chinese.backend. The problem is that even with this configuration, info-level log output from my app is filtered. Evidence:
I've also tried the following config, which yielded the same result (including the logger class name at the end of the package name):
.level = WARNING
nilsnett.chinese.backend.JavaUtilLogger.level = INFO
To demonstrate that the logging.properties-file is actually read, and that I actually do write info-level logging data to app-engine in this service call, let me show you what happens when I set.level=INFO:
So my desired result is to have INFO and higher-level log outputs from my packages, while other packages, like org.datanucleus, only shows output if WARNING or more severe. In the example above, I want only the two lines marked with the purple star. Am I doing anything wrong?
change your config to:
.level = WARNING
# Set the default logging level for the datanucleus loggers
DataNucleus.JDO.level=WARNING
DataNucleus.Persistence.level=WARNING
DataNucleus.Cache.level=WARNING
DataNucleus.MetaData.level=WARNING
DataNucleus.General.level=WARNING
DataNucleus.Utility.level=WARNING
DataNucleus.Transaction.level=WARNING
DataNucleus.Datastore.level=WARNING
DataNucleus.ClassLoading.level=WARNING
DataNucleus.Plugin.level=WARNING
DataNucleus.ValueGeneration.level=WARNING
DataNucleus.Enhancer.level=WARNING
DataNucleus.SchemaTool.level=WARNING
# FinalizableReferenceQueue tries to spin up a thread and fails. This
# is inconsequential, so don't scare the user.
com.google.common.base.FinalizableReferenceQueue.level=WARNING
com.google.appengine.repackaged.com.google.common.base.FinalizableReferenceQueue.level=WARNING
this is are coming from logging config template, so to set datanucleus to warning you have todo like in this template.
https://developers.google.com/appengine/docs/java/#Logging
and then just add your own logging config:
nilsnett.chinese.backend.level = INFO
this should solve it
I am starting to write a MacRuby app. I installed some gems which i am interested in using. I get an error in xmlbase when trying to run.
/Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/builder-3.0.0/lib/builder/xmlbase.rb:in _indent': undefined method*' for nil:NilClass (NoMethodError)
I am using the 0.10 version of the framework. I downloaded the latest daily version to see if its been fixed but when my app runs its still calling the old 0.10 version. How do i get it to reference the newer version. Is this something in Xcode to something specific to MacRuby. Can i use RVM to do this?
Also anyone have any ideas if this has been fixed in a more recent version. The code i am using is as follows. You'll need a bet fair account to test!
require 'rubygems'
require 'betfairapi-savon'
class BetFairTest
def self.test
api = BetfairAPI.new
username = 'username'
password = 'pass'
response = api.login(username, password, 82, 0, 0, nil)
session_token = response.to_hash[:login_response][:result][:header][:session_token]
all_markets = api.get_all_markets(session_token,1)
api.keep_alive(session_token)
api.logout(session_token)
end
end
after the login i get the error
/Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/builder-3.0.0/lib/builder/xmlbase.rb:in `_indent': undefined method `*' for nil:NilClass (NoMethodError)
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:281:in `_special:'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:254:in `instruct!:'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/savon-0.9.7/lib/savon/soap/xml.rb:166:in `builder'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/savon-0.9.7/lib/savon/soap/xml.rb:150:in `to_xml'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/savon-0.9.7/lib/savon/soap/request.rb:38:in `setup:'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/savon-0.9.7/lib/savon/soap/request.rb:23:in `initialize:'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/savon-0.9.7/lib/savon/client.rb:79:in `request:'
from /Library/Frameworks/MacRuby.framework/Versions/0.10/usr/lib/ruby/Gems/1.9.2/gems/betfairapi-savon-1.0.1/lib/betfairapi-savon.rb:17:in `login:'
from /Users/barry/Library/Developer/Xcode/DerivedData/TestApp-djtngswdhcnqvgdwihommmloripf/Build/Products/Debug/TestApp/Contents/Resources/BetFairTest.rb:20:in `test'
Cheers,
Barry.