Pr0d1r2-active_record_connectionless 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
@@ -16,10 +16,12 @@ ActiveRecord::Base.class_eval do
|
|
16
16
|
validate ? valid? : true
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.emulate_attribute(
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def self.emulate_attribute(*names)
|
20
|
+
names.each do |name|
|
21
|
+
attr_accessor name
|
22
|
+
define_method("#{name}_before_type_cast") do
|
23
|
+
self.send(name)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -19,10 +19,12 @@ describe "ActiveRecordConnectionless" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe 'emulate_attribute' do
|
22
|
-
it 'should provide emulate_attribute method that create emulated activerecord
|
23
|
-
ActiveRecordConnectionless.should_receive(:attr_accessor).with(:
|
24
|
-
ActiveRecordConnectionless.should_receive(:define_method).with("
|
25
|
-
ActiveRecordConnectionless.
|
22
|
+
it 'should provide emulate_attribute method that create emulated activerecord attributes' do
|
23
|
+
ActiveRecordConnectionless.should_receive(:attr_accessor).with(:name1)
|
24
|
+
ActiveRecordConnectionless.should_receive(:define_method).with("name1_before_type_cast")
|
25
|
+
ActiveRecordConnectionless.should_receive(:attr_accessor).with(:name2)
|
26
|
+
ActiveRecordConnectionless.should_receive(:define_method).with("name2_before_type_cast")
|
27
|
+
ActiveRecordConnectionless.emulate_attribute(:name1, :name2)
|
26
28
|
end
|
27
29
|
|
28
30
|
it 'should create an method which points to original attribute' do
|
@@ -30,6 +32,13 @@ describe "ActiveRecordConnectionless" do
|
|
30
32
|
active_record_connectionless = ActiveRecordConnectionless.new(:name => 'name')
|
31
33
|
active_record_connectionless.name_before_type_cast.should == 'name'
|
32
34
|
end
|
35
|
+
|
36
|
+
it 'should create methods which points to original attributes for multiple' do
|
37
|
+
ActiveRecordConnectionless.emulate_attribute(:name1, :name2)
|
38
|
+
active_record_connectionless = ActiveRecordConnectionless.new(:name1 => 'name1', :name2 => 'name2')
|
39
|
+
active_record_connectionless.name1_before_type_cast.should == 'name1'
|
40
|
+
active_record_connectionless.name2_before_type_cast.should == 'name2'
|
41
|
+
end
|
33
42
|
end
|
34
43
|
|
35
44
|
end
|