class Account < ActiveRecord::Base INVALID_PAGE_NAMES = Dir[Rails.root.join('app/controllers/*_controller.rb')].map { |path| path.match(/(\w+)_controller.rb/); $1 } validates :page_name, :exclusion => { :in => INVALID_PAGE_NAMES, :message => "Page %{value} is reserved." } end
Tech stuff around computer programming, basically for web development, especially opensource. Topics will go round Ruby on Rails (git gems etc.), Ubuntu (admin and basic shell) and work organization (agile philosophy)
Sunday, 24 February 2013
validates exclusion of controller names when catching all routes
Of course catching all routes is bad, but if you have to:
Saturday, 23 February 2013
rspec, capybara and factorygirl hints
# spec_helper.rb # this line will make rpsec end at the first failing test RSpec.configure do |c| c.fail_fast = true end
# in integration specs # xpath can be copied from chrome, rx-click on the element (in the dev-tool) page.should have_xpath("//a[contains(@href,'users')]"), count: num)
rails sandbox tasks
desc 'do not permanently write on the db (good for testing rake tasks)' task :sandbox => :environment do puts "** << USING SANDBOX!! >> **" # beginning ActiveRecord::Base.connection.increment_open_transactions ActiveRecord::Base.connection.begin_db_transaction # end at_exit do ActiveRecord::Base.connection.rollback_db_transaction ActiveRecord::Base.connection.decrement_open_transactions end end
yaml defaults example (postgres on ruby on rails)
postgres: &postgres adapter: postgresql encoding: unicode host: localhost username: netengine password: development: <<: *postgres database: propertyconnect_development test: <<: *postgres database: propertyconnect_test
Subscribe to:
Posts (Atom)