Created
October 17, 2011 15:10
-
-
Save edipofederle/1292824 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #index controller client | |
| def index | |
| #@clients = Client.where("user_id = ? AND name LIKE ?", current_user.id, "%#{params[:search]}%").order("name ASC") | |
| @clients = current_user.clients.search_by_name(params[:search]) | |
| end | |
| #Model Client | |
| def self.search_by_name(name) | |
| Client.where("name LIKE ?", name).order("name ASC") | |
| end | |
| #Unit Test | |
| let(:current_user) { User.create!(:name => "Fulano", :email => "[email protected]",:password => "secret", :username => "edipofederle")} | |
| let!(:client) { Client.create!(:name => 'Cliente Nome', :email => "[email protected]", :cep=>"10100101", :i_estadual => "191991991",:cpf =>"0101010101", :address => "Rua sem nome", :birthdate => "12/12/1954", :razao_social => "teste", :city => "ibiaca", :state => "RS", :phone => "549494944", :user_id => current_user.id) } | |
| it 'should find the clients by name' do | |
| Client.search_by_name('Cliente Nome').should include(client) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment