datastax_rails 2.0.4 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datastax_rails/base.rb +2 -3
- data/lib/datastax_rails/callbacks.rb +4 -4
- data/lib/datastax_rails/persistence.rb +24 -0
- data/lib/datastax_rails/railtie.rb +7 -0
- data/lib/datastax_rails/schema/solr.rb +3 -0
- data/lib/datastax_rails/version.rb +1 -1
- data/spec/datastax_rails/base_spec.rb +0 -19
- data/spec/datastax_rails/callbacks_spec.rb +48 -0
- data/spec/support/models.rb +0 -21
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515e87cf850c3d9a87ae5b12b2a2ea125ae0af75
|
4
|
+
data.tar.gz: 145680d9780c211dd58172bd8df338df5b245571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0eb3d48eda726e2ae6607df2e5ceb0448ecd7e2181716eba42875e456dc2fd33036492ee1fbccd1f0abb914b03ed3fcf932ca6d42a2caf82e0a70e910445bfd4
|
7
|
+
data.tar.gz: 3108393c7d9fd432f52b45b321fa662e31f777a275721f17cbcb43272464c4da73eba59de3f0ee43c4ea44ee9a79b2dad4ce43217185d605ce1d930a564e8783
|
data/lib/datastax_rails/base.rb
CHANGED
@@ -357,8 +357,8 @@ module DatastaxRails #:nodoc:
|
|
357
357
|
include Batches
|
358
358
|
include AttributeAssignment
|
359
359
|
include AttributeMethods
|
360
|
-
include Callbacks
|
361
360
|
include Validations
|
361
|
+
include Callbacks
|
362
362
|
include Reflection
|
363
363
|
include Associations
|
364
364
|
include Scoping
|
@@ -376,7 +376,7 @@ module DatastaxRails #:nodoc:
|
|
376
376
|
class_attribute :default_timezone, :instance_writer => false
|
377
377
|
self.default_timezone = :utc
|
378
378
|
|
379
|
-
# Stores the default consistency level (QUORUM by default)
|
379
|
+
# Stores the default consistency level (QUORUM by default)
|
380
380
|
class_attribute :default_consistency
|
381
381
|
self.default_consistency = :quorum
|
382
382
|
|
@@ -441,7 +441,6 @@ module DatastaxRails #:nodoc:
|
|
441
441
|
init_internals
|
442
442
|
|
443
443
|
@new_record = false
|
444
|
-
|
445
444
|
run_callbacks :find
|
446
445
|
run_callbacks :initialize
|
447
446
|
end
|
@@ -258,7 +258,7 @@ module DatastaxRails
|
|
258
258
|
:after_initialize, :after_find, :after_touch, :before_validation, :after_validation,
|
259
259
|
:before_save, :around_save, :after_save, :before_create, :around_create,
|
260
260
|
:after_create, :before_update, :around_update, :after_update,
|
261
|
-
:before_destroy, :around_destroy, :after_destroy, :after_commit
|
261
|
+
:before_destroy, :around_destroy, :after_destroy, :after_commit
|
262
262
|
]
|
263
263
|
|
264
264
|
module ClassMethods
|
@@ -276,9 +276,9 @@ module DatastaxRails
|
|
276
276
|
run_callbacks(:destroy) { super }
|
277
277
|
end
|
278
278
|
|
279
|
-
def touch(*) #:nodoc:
|
280
|
-
run_callbacks(:touch) { super }
|
281
|
-
end
|
279
|
+
# def touch(*) #:nodoc:
|
280
|
+
# run_callbacks(:touch) { super }
|
281
|
+
# end
|
282
282
|
|
283
283
|
private
|
284
284
|
|
@@ -147,6 +147,30 @@ module DatastaxRails
|
|
147
147
|
@destroyed = true
|
148
148
|
freeze
|
149
149
|
end
|
150
|
+
|
151
|
+
# TODO: Make this work
|
152
|
+
# def touch(name = nil)
|
153
|
+
# raise ActiveRecordError, "can not touch on a new record object" unless persisted?
|
154
|
+
#
|
155
|
+
# attributes = timestamp_attributes_for_update_in_model
|
156
|
+
# attributes << name if name
|
157
|
+
#
|
158
|
+
# unless attributes.empty?
|
159
|
+
# current_time = current_time_from_proper_timezone
|
160
|
+
# changes = {}
|
161
|
+
#
|
162
|
+
# attributes.each do |column|
|
163
|
+
# column = column.to_s
|
164
|
+
# changes[column] = write_attribute(column, current_time)
|
165
|
+
# end
|
166
|
+
#
|
167
|
+
# @changed_attributes.except!(*changes.keys)
|
168
|
+
# primary_key = self.class.primary_key
|
169
|
+
# self.class.unscoped.where(primary_key => self[primary_key]).update_all(changes) == 1
|
170
|
+
# else
|
171
|
+
# true
|
172
|
+
# end
|
173
|
+
# end
|
150
174
|
|
151
175
|
# Updates a single attribute and saves the record.
|
152
176
|
# This is especially useful for boolean flags on existing records. Also note that
|
@@ -20,6 +20,13 @@ module DatastaxRails
|
|
20
20
|
raise "ERROR: datastax.yml does not define a configuration for #{Rails.env} environment"
|
21
21
|
end
|
22
22
|
DatastaxRails::Base.establish_connection(config[Rails.env].with_indifferent_access)
|
23
|
+
if defined?(PhusionPassenger)
|
24
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
25
|
+
if forked
|
26
|
+
DatastaxRails::Base.establish_connection(config[Rails.env].with_indifferent_access)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
rake_tasks do
|
@@ -24,6 +24,9 @@ module DatastaxRails
|
|
24
24
|
if Rails.root.join('config','solr',"#{model.column_family}-schema.xml.erb").exist?
|
25
25
|
say "Using custom schema for #{model.name}", :subitem
|
26
26
|
ERB.new(Rails.root.join('config','solr',"#{model.column_family}-schema.xml.erb").read, 0, '>').result(binding)
|
27
|
+
elsif Rails.root.join('config','solr','application-schema.xml.erb').exist?
|
28
|
+
say 'Using application default schema', :subitem
|
29
|
+
ERB.new(Rails.root.join('config','solr','application-schema.xml.erb').read, 0, '>').result(binding)
|
27
30
|
else
|
28
31
|
ERB.new(File.read(File.join(File.dirname(__FILE__),"..","..","..","config","schema.xml.erb")), 0, '>').result(binding)
|
29
32
|
end
|
@@ -1,25 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DatastaxRails::Base do
|
4
|
-
it "should run before_save" do
|
5
|
-
p = Person.new(:name => "Jason")
|
6
|
-
p.save
|
7
|
-
p.nickname.should == "Jason"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should run after_save" do
|
11
|
-
p = Person.new(:name => "Steve")
|
12
|
-
p.save
|
13
|
-
p.instance_variable_get(:@after_save_ran).should == "yup"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should run after_create" do
|
17
|
-
p = Person.new(:name => "Tommy")
|
18
|
-
p.save
|
19
|
-
p.instance_variable_get(:@after_create_ran).should == "yup"
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
4
|
it "should raise RecordNotFound when finding a bogus ID" do
|
24
5
|
lambda { Person.find("xyzzy") }.should raise_exception(DatastaxRails::RecordNotFound)
|
25
6
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CallbackTester < Hobby
|
4
|
+
self.column_family = "hobbies"
|
5
|
+
attr_accessor :after_find_called, :after_initialize_called
|
6
|
+
|
7
|
+
after_find { self.after_find_called = true }
|
8
|
+
after_initialize { self.after_initialize_called = true }
|
9
|
+
|
10
|
+
%w[before_save before_create after_save after_create before_validation after_validation
|
11
|
+
after_touch before_destroy after_destroy].each do |callback|
|
12
|
+
self.send(callback, callback + "_callback") # after_save 'after_save_callback'
|
13
|
+
define_method(callback+"_callback") do
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe DatastaxRails::Base do
|
20
|
+
describe "callbacks" do
|
21
|
+
subject { CallbackTester.new }
|
22
|
+
|
23
|
+
%w[before_save before_create after_save after_create before_validation after_validation].each do |callback|
|
24
|
+
it "runs #{callback}" do
|
25
|
+
expect(subject).to receive(callback+"_callback")
|
26
|
+
subject.save
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
%w[after_destroy before_destroy].each do |callback|
|
31
|
+
it "runs #{callback}" do
|
32
|
+
subject.save
|
33
|
+
expect(subject).to receive(callback+"_callback")
|
34
|
+
subject.destroy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "runs after_find" do
|
39
|
+
subject.save
|
40
|
+
ct=CallbackTester.find(subject.id)
|
41
|
+
expect(ct.after_find_called).to be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "runs after_initialize" do
|
45
|
+
expect(subject.after_initialize_called).to be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/support/models.rb
CHANGED
@@ -13,28 +13,7 @@ class Person < DatastaxRails::Base
|
|
13
13
|
map :str_
|
14
14
|
timestamps
|
15
15
|
|
16
|
-
before_create :set_variable2
|
17
|
-
before_save :set_nickname
|
18
|
-
after_save :set_variable
|
19
|
-
after_create :set_variable3
|
20
|
-
|
21
16
|
validates :name, :presence => true, :uniqueness => :true
|
22
|
-
|
23
|
-
def set_nickname
|
24
|
-
self.nickname ||= self.name
|
25
|
-
end
|
26
|
-
|
27
|
-
def set_variable
|
28
|
-
@after_save_ran = "yup"
|
29
|
-
end
|
30
|
-
|
31
|
-
def set_variable2
|
32
|
-
@before_create_ran = "yup"
|
33
|
-
end
|
34
|
-
|
35
|
-
def set_variable3
|
36
|
-
@after_create_ran = 'yup'
|
37
|
-
end
|
38
17
|
end
|
39
18
|
|
40
19
|
class Car < DatastaxRails::Base
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datastax_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason M. Kusar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -243,6 +243,7 @@ files:
|
|
243
243
|
- spec/datastax_rails/associations_spec.rb
|
244
244
|
- spec/datastax_rails/attribute_methods_spec.rb
|
245
245
|
- spec/datastax_rails/base_spec.rb
|
246
|
+
- spec/datastax_rails/callbacks_spec.rb
|
246
247
|
- spec/datastax_rails/column_spec.rb
|
247
248
|
- spec/datastax_rails/cql/select_spec.rb
|
248
249
|
- spec/datastax_rails/cql/update_spec.rb
|
@@ -362,6 +363,7 @@ test_files:
|
|
362
363
|
- spec/datastax_rails/inheritance_spec.rb
|
363
364
|
- spec/datastax_rails/associations/has_many_association_spec.rb
|
364
365
|
- spec/datastax_rails/associations/belongs_to_association_spec.rb
|
366
|
+
- spec/datastax_rails/callbacks_spec.rb
|
365
367
|
- spec/feature/dynamic_fields_spec.rb
|
366
368
|
- spec/feature/overloaded_tables_spec.rb
|
367
369
|
- spec/spec.opts
|