Sandi Metz, great post

sandimetzlogoA great post from Sandi, regarding wrong abstraction when coding: http://www.sandimetz.com/blog/2016/1/20/the-wrong-abstraction. I’ve seen myself in such a situation a lot of times, so time to change things! 馃檪

Escrito en Programaci贸n, Ruby|Programaci贸n, Ruby n idatzia|Posted in Programaci贸n, Ruby | Tagged , | Deja un comentario|Idatzi zure iritzia|Leave a comment

New project published

Ruby code repository at Bitbucket.orgI have recently published a small project at Bitbucket, called “view_reports”. This small project allows people to connect to a database and get a tiny report of a table from that database. The main key is that uses Yubikey [1] [2] for two-factor authentication (a Yubikey and a PIN). Other than that is a very simple application now (and I want to keep it like so). I have used Sequel, Sinatra as main components. Comments are very welcome 馃檪

Cheers 馃檪

Escrito en Programaci贸n, Ruby, Software, Software Libre|Programaci贸n, Ruby, Software, Software Libre n idatzia|Posted in Programaci贸n, Ruby, Software, Software Libre | Tagged , , , , | Deja un comentario|Idatzi zure iritzia|Leave a comment

Query SQLite looking for boolean records

rubyToday I have needed to ask an SQLite DB to get some records with a field set to true, and all my first attempts to do it have been failed. Finally I have achieved it, and I would like to share this little achievement 馃檪

NOT working:

Model.find(:all, :conditions => 'field = true')

NOT working:

Model.find(:all, :conditions => 'field = "true"')

NOT working:

Model.find(:all, :conditions => 'field = 1')

NOT working:

Model.find(:all, :conditions => 'field = "1"')

and finally working:

Model.find(:all, :conditions => 'field = "t"')

The solution has consisted on looking at DB level, which is the real data stored on it. Cheers 馃檪

Escrito en Programaci贸n|Programaci贸n n idatzia|Posted in Programaci贸n | Tagged , , , , , , , | Deja un comentario|Idatzi zure iritzia|Leave a comment

Dinamyc callbacks on Rails, is it possible?

Today I have tried to do this: let any application application, and among all the tables to storage the data of your model estructure, there is one called “Configuration”. As you can suspect, this table will storage some configuration options for your application. For some configuration options you need to execute certain code, and here is what I’ve tried:

class Configuration < ActiveRecord::Base
# These next lines are related to Hobo gem, and are just 
# an expression to define the model (you can imagine what they do for sure)
  fields do
    name :string
    value :string
    callback :boolean, default => false
    callback_name :string
end

after_update self.callback_name.to_sym, :if => self.callback?
... here comes the definition of each callback ...

For some reason this is not allowed. I think this is a nice solution to hook configuration options within code, but it doesn’t seem to work :/

If any of you get something like this working, please let me know, I will own a beer (no alcohol obviously 馃檪

Cheers, Ibon.

Escrito en Programaci贸n|Programaci贸n n idatzia|Posted in Programaci贸n | Tagged , , | Deja un comentario|Idatzi zure iritzia|Leave a comment

Capybara screenshot on ancient Rails 2.3.X projects

Recently I’ve been playing with some tests on an old Rails Project. In terms of actual Computer Science Mesure Units or CSMUs, this is quite old (remember that one CSMU is the time used by a user to change his/hers iPhone 馃檪

Some failures on the test forced me to look up for some solutions and Capybara-screenshot was one of the elected ones, instead of being playing around with messages on the log file. The sad side of recent versions of this gem is that it seemed not to play well with Rails 2.3 infrastructure. There is a Rails 2.3 compatible version but some of the usual methods of Capybara-screenshot were not working well.

What I have founded is this recipe running for me: install capybara-screenshot 0.3.14, then require it on your spec_helper.rb file. When your test fails the screenshot is not being automatically taken (at least in my case), but you can use it manually, before the offending line by putting “screenshot_and_open_image” 馃檪

Cheers.

Escrito en Programaci贸n|Programaci贸n n idatzia|Posted in Programaci贸n | Tagged , , , | Deja un comentario|Idatzi zure iritzia|Leave a comment