This file contains 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
# It was working normally. I had added some dynamic fields to solr/conf/schema.xml. Then I git cloned again (after removing the project directory), same machine, and started getting this errors: | |
RSolr::Error::Http - 400 Bad Request | |
Error: ERROR:unknown field 'name_textp' | |
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">Good 12</field><field name=\"type\">Good</field><field name=\"type\">ActiveRecord::Base</field><field name=\"class_name\">Good</field><field name=\"company_id_i\">1</field><field name=\"name_textp\">hber</field></doc></add>" | |
Backtrace: /Users/kurko/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rsolr-1.0.7/lib/rsolr/client.rb:230:in `adapt_response' | |
/Users/kurko/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rsolr-1.0.7/lib/rsolr/client.rb:167:in `execute' | |
/Users/kurko/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/rsolr-1.0.7/lib/rsolr/client.rb:161:in `send_and_receive' |
This file contains 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
class PostCommitmentContext | |
def initialize(params) | |
@params = params | |
end | |
def save | |
@post = Post.new(@params) | |
if @post.save | |
# @post é ActiveRecord, então não há o que extender mesmo porque ActiveRecord já está encruado | |
@twitter = Twitter.login("username", "password") |
This file contains 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
# A controller | |
class PostsController < ActionController::Base | |
def create | |
@context = PostManagementContext.new(params[:posts]) | |
if @context.save | |
# redirect | |
end | |
end | |
def search |
This file contains 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
class ReceivablesManagementContext | |
def initialize(params) | |
@params = params | |
end | |
def save_receivable | |
sanitize_controller_params | |
@receivable = AccountReceivable.new(@params[:account_receivable]) | |
@receivable.customer_id = @params[:customer_id] | |
@receivable.save |
This file contains 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
# no terminal, rodar: | |
# | |
# ruby -v | |
# | |
# retorna 1.8.7 ou 1.9.x | |
array_one = [] | |
puts array_one.count # => 0 | |
array_two = [:first, :second, :third] |
This file contains 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
proxies.each do |method_name, dependency| | |
if model.class.ancestors.include?(dependency) || dependency.nil? | |
class << self | |
# The line below raises: | |
# undefined method `method_name' for Product:Class | |
# class << self is changing the scope, how can I get `method_name` from | |
# the each iterator? | |
self.send(:define_method, method_name) do |*args, &block| | |
model.send(method_name, *args, &block) | |
end |
This file contains 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
module Accounts | |
class Company | |
def my_method | |
end | |
end | |
class Person | |
def whatever |
This file contains 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
1 # Rails | |
2 module ActiveRecord | |
3 class Base | |
4 def created_at | |
5 "21/04/1987" | |
6 end | |
7 end | |
8 end | |
9 | |
10 # model |
This file contains 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
class Bank | |
def transfer(from, to, amount) | |
transfer = Transfer.new(from, to, amount) | |
transfer.transfer | |
end | |
end | |
class Transfer | |
def initialize(from, to, amount) | |
@from = from |
This file contains 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
class Car | |
def run | |
"The car is running" | |
end | |
end | |
# RSpec example | |
describe "#run" do | |
it "should run" do | |
Car.new.run.should == "The car is running" |