Rails 3 cache not working. Dalli - ruby

development.rb cache configuration
config.action_controller.perform_caching = true
config.cache_store = :dalli_store, 'localhost:11211',
{ :namespace => APP_NAME, :expires_in => 3.month, :compress => true }
production.rb cache configuration
config.action_controller.perform_caching = true
config.cache_store = :dalli_store, 'localhost:11211',
{ :namespace => APP_NAME, :expires_in => 3.month, :compress => true }
in console
rails c production
Loading production environment (Rails 3.2.3)
1.9.3-p125 :001 > Rails.cache.write 'res', "Hello World"
=> true
1.9.3-p125 :002 > Rails.cache.read 'res'
=> nil
1.9.3-p125 :003 >
Why?

memcached has a limit of 30 days if you defined the expiry that way - Memcache maximum key expiration time
Also see https://github.com/mperham/dalli/issues/55

Related

Set secure session Cookie in Rails 2

I have a Rails 2 application. And I want to set the session cookie to secure. By default it will be http only.To implement the same, I added the :secure=> true in config/initializers/session_store.rb as below:
ActionController::Base.session = {
:key => '_app_session',
:secret => '123.......',
:secure => true
}
But it does not work. However, the same thing works well in Rails 3.
This worked for me in the past. In config/environment.rb:
config.action_controller.session = {
:session_key => '_app_session',
:secret => '123.......',
:secure => true
}

ChromeOptions To Not Prompt For Download When Running RemoteDriver

I'm trying to debug why when running remote webdriver tests on a headless linux host download dialogs are presented in chrome. I believe the chrome version is 45.
Couple of Env Details
Selenium 2.53 (gem)
Selenium 2.53 Server Jar
Chrome Driver 2.21
The framework/Tests are written in Ruby utilizing Capybara for driving web tests. Here is a brief snippet of how the remote driver is initialized.
prefernces = {
:download => {
:prompt_for_download => false,
:default_directory => '/home/john.doe/Downloads/'
}
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome()
caps['chromeOptions'] = {'prefs' => prefernces}
http_client = Selenium::WebDriver::Remote::Http::Default.new
http_client.timeout = 240
options = {
browser: :remote,
url: "http://<server_url>:4444/wd/hub",
desired_capabilities: caps,
http_client: http_client
}
# Returns Remote Driver
Capybara::Selenium::Driver.new(app, options)
I have verified via the hub that the chromeOptions are set, but when a file is downloaded, we're presented with a file dialog prompt.
I've burned the candle looking for a solution to this problem. Thanks for the help and consideration!
try removing the / from the end of the default_directory and also setting directory_upgrade: true. Other than that make sure the browser has permission to write to the selected directory (note also the correct spelling of preferences)
preferences = {
:download => {
:default_directory => '/home/john.doe/Downloads',
:directory_upgrade => true,
:prompt_for_download => false,
}
}
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {'prefs' => preferences}
)
Here is an example to download a file with Capybara / Selenium / Chrome :
require 'capybara'
require 'selenium-webdriver'
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app,
:url => "http://localhost:4444/wd/hub",
:browser => :chrome,
:desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'prefs' => {
'download.default_directory' => File.expand_path("C:\\Download"),
'download.directory_upgrade' => true,
'download.prompt_for_download' => false,
'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
}
}
)
)
end
session = Capybara::Session.new(:chrome)
session.visit "https://www.mozilla.org/en-US/foundation/documents"
session.click_link "IRS Form 872-C"
sleep 20

How to use Net::LDAP with JRuby

I am using Ruby and JRuby on a Ubuntu machine through RVM.
OpenLDAP is connecting and doing the CRUD operation through Ruby code with the Net::LDAP gem perfectly.
Here is the code:
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new :host => 'locahost',
:port => 389,
:async => 1,
:keepalive => 1,
:auth => {
:method => :simple,
:username => "cn=admin,dc=test,dc=com",
:password => "secret"
}
puts ldap.bind
When I execute the same code with JRuby, it throws an error:
$ jruby ldap_test.rb
ArgumentError: unsupported protocol family `__UNKNOWN_CONSTANT__'
initialize at org/jruby/ext/socket/RubySocket.java:188
new at org/jruby/RubyIO.java:847

How to setup a mail interceptor in rails 3.0.3?

I am using rails 3.0.3, ruby 1.9.2-p180, mail (2.2.13). I m trying to setup a mail interceptor but I am getting the following error
/home/abhimanyu/Aptana_Studio_3_Workspace/delivery_health_dashboard_03/config/initializers/mailer_config.rb:16:in `<top (required)>': uninitialized constant DevelopmentMailInterceptor (NameError)
How do i fix it?
The code I am using is shown below:
config/initializer/mailer_config.rb
ActionMailer::Base.default_charset = "utf-8"
ActionMailer::Base.default_content_type = "text/html"
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:enable_starttls_auto => true,
:address => "secure.emailsrvr.com",
:port => '25',
:domain => "domain",
:user_name => "user_name",
:password => "password",
:authentication => :plain
}
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
lib/development_mail_interceptor.rb
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.to = "email"
end
end
Thanks in advance.
require 'development_mail_interceptor' #add this line
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
I found it easier to install the mailcatcher gem. Then in development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "`localhost`",
:port => 1025
}
Then just run "mailcatcher" and hit http://localhost:1080/ in a browser. It runs in the background, but can be quit directly from the browser. Gives you text+html views, source, and analysis with fractal, if you swing that way. Super-clean.

ruby daemons - running but not functioning

I have created my first ruby daemon and it functions fine for about a day but then it stops functioning but it still appears in the /var/run folder.
here is my control code -
require 'rubygems'
require 'daemons'
dir = File.dirname(__FILE__)
options = {
:app_name => "rk_mail",
:dir_mode => :system,
:backtrace => true,
:log_output => true,
:monitor => true
}
Daemons.run(dir + '/mail_receiver.rb', options)
I have checked the logs but they dont show any errors
Thanks, alex
The problem is that your script will change its directory to "/" when it starts the daemon process.
Here's a way to fix it:
current_dir = Dir.pwd
options = {
:backtrace => true,
:app_name => "test",
:log_dir => "#{current_dir}/log",
:log_output => true,
:dir_mode => :normal,
:monitor => true
}
This will put the logs inside the log folder that's the same directory as your script.

Resources