Pr0d1r2-active_record_connectionless 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_record_connectionless}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcin Nowicki"]
@@ -16,10 +16,12 @@ ActiveRecord::Base.class_eval do
16
16
  validate ? valid? : true
17
17
  end
18
18
 
19
- def self.emulate_attribute(name)
20
- attr_accessor name
21
- define_method("#{name}_before_type_cast") do
22
- self.name
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 attribute' do
23
- ActiveRecordConnectionless.should_receive(:attr_accessor).with(:name)
24
- ActiveRecordConnectionless.should_receive(:define_method).with("name_before_type_cast")
25
- ActiveRecordConnectionless.emulate_attribute(:name)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Pr0d1r2-active_record_connectionless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Nowicki