samedi 2 juillet 2016

Rspec expect not working and getting success

I wrote the following code:

require_relative '../ticket'
describe Ticket do
  before do
    @ticket = Ticket.new()
  end
# context "check_ticket" do
#   it 'check_a_ticket' do
#     @ticket.stub(:gets) {"quit"}
#     expect(@ticket.show_tickets(1)).to be_present
#   end
# end
# context "check_tickets" do
#   it 'check_tickets' do
#     t@icket.stub(:gets) {"menu"}
#     expect(@ticket.ticket_viewer(1)).to be_present
#   end
# end
  context "exit" do
    it 'check_exit' do
      result = @ticket.ticket_viewer("quit")
      expect(result).to include("Thanks")
    end
  end
end

When I try to execute,

expect(result).to eq("something")

does not work. The case is passed no matter what the value is in eg("something"). Help please.

undefined method translate during Rails 2.3 -> 3.2 upgrade

Working on upgrading a Rails 2.3.17 app to Rails 3.2.22.2 (running ruby 1.9.3-p551). Was able to get through the painful portion of ugprading all the gems / updating the directory structure / adding in all new/updated rails files.

The rails server is now coming up, but when i try to load up the first page, it fails with this stack trace:

NoMethodError: undefined method `translate' for #   <I18n::Backend::ActiveRecord:0x007ff64dc72400>
/myapp/vendor/bundle/ruby/1.9.1/gems/i18n-0.7.0/lib/i18n/backend/chain.rb:46:in `block (2 levels) in translate'
/myapp/vendor/bundle/ruby/1.9.1/gems/i18n-0.7.0/lib/i18n/backend/chain.rb:44:in `catch'
/myapp/vendor/bundle/ruby/1.9.1/gems/i18n-0.7.0/lib/i18n/backend/chain.rb:44:in `block in translate'
/myapp/vendor/bundle/ruby/1.9.1/gems/i18n-0.7.0/lib/i18n/backend/chain.rb:43:in `each'

...

Additional notes: I have an locale.rb file in the config/initializers/ folder, which has this:

require "i18n/backend/cache"

I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Flatten)
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
I18n::Backend::Chain.send(:include, I18n::Backend::Cache)
I18n.backend = I18n::Backend::ActiveRecord.new
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Simple.new, I18n.backend)

any ideas why it might be generating that error message ?

vendredi 1 juillet 2016

RubyMine JRuby-1.7.0 Breakpoint from Unit Test or Script

My environment:

JRuby-1.7.0

Rails 3.0.0

RubyMine 2016.1.2

I can set a breakpoint successfully when launching the full webapp using rails s:

/home/user/.rvm/rubies/jruby-1.7.0/bin/jruby --1.9 -X+O -J-Djruby.compile.mode=OFF -J-Djruby.debug.fullTrace=true -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)        /home/user/.rvm/gems/jruby-1.7.0/gems/ruby-debug-ide-0.6.1.beta2/bin/rdebug-ide --disable-int-handler --evaluation-timeout 10 --rubymine-protocol-extensions --port 55357 --host 0.0.0.0 --dispatcher-port 47578 -- /home/user/dev/share/app/script/rails server -b 0.0.0.0 -p 3000 -e development

but when I run a script or a simple test with:

/home/user/.rvm/rubies/jruby-1.7.0/bin/jruby --1.9 -X+O -J-Djruby.compile.mode=OFF -J-Djruby.debug.fullTrace=true -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)        /home/user/.rvm/gems/jruby-1.7.0/gems/ruby-debug-ide-0.6.1.beta2/bin/rdebug-ide --disable-int-handler --evaluation-timeout 10 --rubymine-protocol-extensions --port 41191 --host 0.0.0.0 --dispatcher-port 48760 -- /home/user/dev/share/app/test/standalone/exercise_some_code.rb

or:

/home/user/.rvm/rubies/jruby-1.7.0/bin/jruby --1.9 -X+O -J-Djruby.compile.mode=OFF -J-Djruby.debug.fullTrace=true -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Itest /home/user/.rvm/gems/jruby-1.7.0/gems/ruby-debug-ide-0.6.1.beta2/bin/rdebug-ide --disable-int-handler --evaluation-timeout 10 --rubymine-protocol-extensions --port 40324 --host 0.0.0.0 --dispatcher-port 39000 -- /home/user/dev/share/app/test/unit/some_test.rb --name=test_incident_date

The breakpoint is ignored. Any thoughts? I am out of ideas here.

Installed gems:

abstract (1.0.0) actionmailer (3.0.0, 2.3.4) actionpack (3.0.0, 2.3.4) activemodel (3.0.0) activerecord (3.0.0, 2.3.4) activerecord-jdbc-adapter (1.1.3) activerecord-jdbcmysql-adapter (1.1.3) activeresource (3.0.0, 2.3.4) activesupport (3.0.0, 2.3.4) acts_as_list (0.7.4) arel (1.0.1) builder (2.1.2) bundler (1.0.22) bundler-unload (1.0.2) columnize (0.9.0) dbi (0.4.5) debugger-ruby_core_source (1.3.8) deprecated (2.0.1) erubis (2.6.6) executable-hooks (1.3.2) gem-wrappers (1.2.7) i18n (0.7.0, 0.4.2) jdbc-mysql (5.1.22) jruby-launcher (1.1.1 java) jruby-openssl (0.9.17 java) json (1.8.3 java) linecache (1.3.1 java) mail (2.2.20) mime-types (1.25.1) minitest (5.9.0) net-ldap (0.11) polyglot (0.3.5) power_assert (0.3.0) rack (1.2.8, 1.0.1) rack-mount (0.6.14) rack-test (0.5.7) rails (3.0.0, 2.3.4) railties (3.0.0) rake (11.2.2, 0.9.2.2) ruby-debug (0.10.6) ruby-debug-base (0.10.6 java) ruby-debug-ide (0.6.1.beta2) rubygems-bundler (1.4.4) rvm (1.11.3.9) test-unit (3.2.0) thor (0.14.6) thread_safe (0.3.5 java) treetop (1.4.15) tzinfo (1.2.2, 0.3.50) will_paginate (3.1.0)

Rails 3.2.3, how to config Memcached::dalli correctly in my production env

First of all, i introduce my situation :

My web apps is an OA(office assistance) system. i have one server hosting for all my clients, each client has a subdomain like http://ift.tt/297plFv to access to web apps. For example: There are three different clients, and their website link like :

...
http://ift.tt/297plFv
http://ift.tt/298bT0F
http://ift.tt/297psRw
...

Via Nginx + Thin, each website has his own port like this:

...
http://ift.tt/297plFv => my_ip_address:3000
http://ift.tt/298bT0F => my_ip_address:3001
http://ift.tt/297psRw => my_ip_address:3002
...

As you know, each website has his own environement :

Nginx
/etc/nginx/sites-available/3000-subdomain1
/etc/nginx/sites-available/3001-subdomain2
/etc/nginx/sites-available/3002-subdomain3

Thin
/etc/thin/3000-subdomain1.yml
/etc/thin/3001-subdomain2.yml
/etc/thin/3002-subdomain3.yml

Envs:
config/environments/subdomain1.rb # production mode
config/environments/subdomain2.rb # production mode
config/environments/subdomain3.rb # production mode

My question is how to config cache_store ? i use Memcached :: Dalli

I tried do this in config/environments/subdomain1.rb:

...
config.cache_store = :dalli_store, 'subdomain1.myapp.com',{ :namespace => Myapp, :expires_in => 1.day, :compress => true }
...

But i have doute for the second and third parameter subdomain1.myapp.com , :namespace => Myapp, Shoud i use my_ip_address:[port] or true url like (subdomain1.myapp.com) or just 127.0.0.1:[port] or nil ? Why ?

Shoud i remove the namespace or not ? Why ?

Any suggestion is welcome Thank you.

Login from YII website to ROR website

I am working on two sites one is in ruby on rails and other is in YII. I want to connect my YII website with ROR website. Like user can login from YII website to the ROR website. If user is login first time from YII website ROR login window will open then he will need to enter email and password and after login into the ROR website, YII website will receive the response and next time user will login directly after clicking on the button. Same as we use Facebook login into our website. I am using Devise login in ROR website. Is there any easy way to integrate this? Anyone please suggest

html_safe not working on dynamic prepared string in Rails

I am preparing a url with dynamic query parameters. I have to place "?" character dynamically. But when I form the link string and call html_safe, but its not working.

Here is my code:

sandbox_mode = sandbox_mode? ? "?sandbox_mode=true" : ""
q_link = "<a href='/users/comments#{sandbox_mode}"
q_link += q_link.include?("?") ? "&" : "?"
q_link += "xyz=abx&abc=ttt"

q_link.html_safe

When I did this it shown a string in email, its not preparing link.

When I try like this, it works fine

"<a href='/users/comments?sandbox_mode=true?xyz=abx&abc=ttt</a>".html_safe

Please help where I am wrong.

Rails 3.2.3, Why my view cached is not stable?

Before asking my question, i read document configurigng Rails Applications

and i still don't know reason why my view cached is not working stably. In my case, after updating the codes in views, sometimes i don't need restart application server(Thin) and the views is reloaded with the modifications Seen that the controllers and models are not reloaded, so my app crashes ... Strange, this problem is not always there it's not stably. sometimes all is ok.

my config production mode like this:

...
# Code is not reloaded between requests
  config.cache_classes = true
...

From the documentation, i learned that if i set true to config.cache_classes, i don't need to set true to config.action_view.cache_template_loading it will follow cache_classes configuring.

I think that cache_classes controls if all classes, modules and views templates will reload for each request. am i right ? any suggestion is welcome.