Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
source :rubygems
gemspec

gem "pry"
38 changes: 27 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@ PATH
remote: .
specs:
elastictastic (0.11.2)
activemodel (~> 3.0)
activesupport (~> 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
hashie
i18n
multi_json

GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
builder (3.0.4)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
atomic (1.1.12)
builder (3.1.4)
coderay (1.0.9)
diff-lcs (1.2.1)
fakeweb (1.3.0)
hashie (2.0.3)
hashie (2.0.5)
i18n (0.6.4)
multi_json (1.7.2)
method_source (0.8.2)
minitest (4.7.5)
multi_json (1.7.7)
pry (0.9.12.2)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
Expand All @@ -31,6 +42,10 @@ GEM
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.0)
slop (3.4.6)
thread_safe (0.1.2)
atomic
tzinfo (0.3.37)
yard (0.8.5.2)

PLATFORMS
Expand All @@ -39,5 +54,6 @@ PLATFORMS
DEPENDENCIES
elastictastic!
fakeweb (~> 1.3)
pry
rspec (~> 2.0)
yard (~> 0.6)
4 changes: 2 additions & 2 deletions elastictastic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ DESC
s.has_rdoc = true
s.extra_rdoc_files = 'README.md'
s.required_ruby_version = '>= 1.9'
s.add_runtime_dependency 'activesupport', '~> 3.0'
s.add_runtime_dependency 'activemodel', '~> 3.0'
s.add_runtime_dependency 'activesupport', '>= 3.0'
s.add_runtime_dependency 'activemodel', '>= 3.0'
s.add_runtime_dependency 'hashie'
s.add_runtime_dependency 'i18n'
s.add_runtime_dependency 'multi_json'
Expand Down
3 changes: 1 addition & 2 deletions lib/elastictastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ module Elastictastic
autoload :Document, 'elastictastic/document'
autoload :MassAssignmentSecurity, 'elastictastic/mass_assignment_security'
autoload :NestedCollectionProxy, 'elastictastic/nested_collection_proxy'
autoload :Observer, 'elastictastic/observer'
autoload :Observing, 'elastictastic/observing'
autoload :ParentChild, 'elastictastic/parent_child'
autoload :Rotor, 'elastictastic/rotor'
autoload :TestHelpers, 'elastictastic/test_helpers'
Expand Down Expand Up @@ -200,4 +198,5 @@ def Index(name_or_index)
end
end


require 'elastictastic/railtie' if defined? Rails
2 changes: 1 addition & 1 deletion lib/elastictastic/basic_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Elastictastic
# The top-level module mixed in to classes which will be mapped as
# ElasticSearch documents. Note that most people will want to use the Document
# mixin, which extends BasicDocument with ActiveModel functionality such as
# validations, lifecycle hooks, observers, mass-assignment security, etc. The
# validations, lifecycle hooks, mass-assignment security, etc. The
# BasicDocument module is exposed directly for those who wish to avoid the
# performance penalty associated with ActiveModel functionality, or those who
# wish to only mix in the ActiveModel modules they need.
Expand Down
6 changes: 1 addition & 5 deletions lib/elastictastic/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ def default_host

def url_from_env
return @url_from_env if defined? @url_from_env
@url_from_env =
@url_from_env =
if ENV['ELASTICSEARCH_URL']
URI.parse(ENV['ELASTICSEARCH_URL'])
end
end

ActiveModel::Observing::ClassMethods.public_instance_methods(false).each do |method|
delegate method, :to => :"::Elastictastic::Observing"
end
end
end
2 changes: 1 addition & 1 deletion lib/elastictastic/dirty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def define_embed(embed_name, options)

private

#
#
# We have to rewrite ActiveModel functionality here because in Rails 3.0,
# #define_attribute_methods has to be called exactly one time, and there's
# no place for us to do that. This appears to be fixed in ActiveModel 3.1
Expand Down
1 change: 0 additions & 1 deletion lib/elastictastic/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Document
included do
include BasicDocument
include Callbacks
include Observing
include Dirty
include MassAssignmentSecurity
include Validations
Expand Down
16 changes: 11 additions & 5 deletions lib/elastictastic/mass_assignment_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ module Elastictastic
module MassAssignmentSecurity
extend ActiveSupport::Concern

included do
include ActiveModel::MassAssignmentSecurity
end
if ActiveModel.version.version < '4.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't one just check for defined? ActiveModel::MassAssignmentSecurity or somesuch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a WIP- wasn't sure how much work would be needed for
compatibility and how far-reaching the changes would be. Perhaps a module
will be overkill.

On Wednesday, August 7, 2013, Mat Brown wrote:

In lib/elastictastic/mass_assignment_security.rb:

@@ -2,12 +2,18 @@ module Elastictastic
module MassAssignmentSecurity
extend ActiveSupport::Concern

  • included do
  •  include ActiveModel::MassAssignmentSecurity
    
  • end
  • if ActiveModel.version.version < '4.0'

Couldn't one just check for defined? ActiveModel::MassAssignmentSecurityor somesuch?


Reply to this email directly or view it on GitHubhttps://github.com//pull/32/files#r5645039
.

included do
include ActiveModel::MassAssignmentSecurity
end

def attributes=(attributes)
super(sanitize_for_mass_assignment(attributes))
def attributes=(attributes)
super(sanitize_for_mass_assignment(attributes))
end
else
def attributes=(attributes)
super(attributes.tap {|attrs| attrs.delete(:index)})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure about this – seems more like whatever is passing an :index attribute shouldn't be.

Also attributes.except(:index) would be a little slicker on this particular line.

end
end
end
end
3 changes: 0 additions & 3 deletions lib/elastictastic/observer.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/elastictastic/observing.rb

This file was deleted.

9 changes: 0 additions & 9 deletions lib/elastictastic/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,5 @@ class Railtie < Rails::Railtie
require 'elastictastic/new_relic_instrumentation' if defined? NewRelic
end

initializer "elastictastic.instantiate_observers" do
config.after_initialize do
::Elastictastic::Observing.instantiate_observers

ActionDispatch::Callbacks.to_prepare do
::Elastictastic::Observing.instantiate_observers
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/environment.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'bundler'
Bundler.require(:default, :test, :development)

%w(author blog comment photo post post_observer).each do |model|
%w(author blog comment photo post).each do |model|
require File.expand_path("../models/#{model}", __FILE__)
end
2 changes: 1 addition & 1 deletion spec/examples/mass_assignment_security_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('../spec_helper', __FILE__)

describe Elastictastic::MassAssignmentSecurity do
describe Elastictastic::MassAssignmentSecurity, compatibility: :active_model_4 do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it the other way around? (not compatible with active model 4?)

let(:post) { Post.new(:title => 'hey guy', :comments_count => 3) }

it 'should allow allowed attributes' do
Expand Down
4 changes: 2 additions & 2 deletions spec/examples/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
it 'should log get requests to logger' do
FakeWeb.register_uri(:get, "http://localhost:9200/default/post/1", :body => '{}')
client.get('default', 'post', '1')
io.string.should == "ElasticSearch GET (3ms) /default/post/1\n"
io.string.should include "ElasticSearch GET (3ms) /default/post/1\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no particular objection to this approach, but another would be to just initialize the logger with a no-op Formatter, I think.

end

it 'should log body of POST requests to logger' do
stub_es_create('default', 'post')
client.create('default', 'post', nil, {})
io.string.should == "ElasticSearch POST (3ms) /default/post {}\n"
io.string.should include "ElasticSearch POST (3ms) /default/post {}\n"
end
end
Loading