acts_as_customized_attributes 0.0.5 → 0.0.6
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.
- checksums.yaml +8 -8
- data/README.md +10 -1
- data/app/models/acts_as_customized_attributes/data.rb +27 -1
- data/app/models/acts_as_customized_attributes/data_key.rb +26 -8
- data/lib/acts_as_customized_attributes/class_methods.rb +4 -7
- data/lib/acts_as_customized_attributes/instance_methods.rb +23 -4
- data/lib/acts_as_customized_attributes/version.rb +1 -1
- data/spec/dummy/log/test.log +5232 -0
- data/spec/models/user_spec.rb +21 -15
- metadata +16 -2
data/spec/models/user_spec.rb
CHANGED
@@ -5,12 +5,13 @@ describe User do
|
|
5
5
|
let!(:order){ create :order, user: user }
|
6
6
|
|
7
7
|
before do
|
8
|
+
UserDataKey.update_cache_name_to_id
|
9
|
+
|
8
10
|
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
11
|
+
user.customized_attribute(:facebook_email).should eq "kaspernj@facebook.com"
|
9
12
|
end
|
10
13
|
|
11
14
|
it "should be possible to set custom data and it shouldn't mix up" do
|
12
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
13
|
-
|
14
15
|
order.update_customized_attributes(affiliate_data: "test")
|
15
16
|
order.customized_attributes[:affiliate_data].should eq "test"
|
16
17
|
order.customized_attributes[:facebook_email].should eq nil
|
@@ -24,17 +25,12 @@ describe User do
|
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should help search for attributes" do
|
27
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
28
|
-
|
29
28
|
users_query = User.where_customized_attribute(:facebook_email, "kaspernj@facebook.com")
|
30
29
|
users_query.count.should eq 1
|
31
30
|
users_query.first.should eq user
|
32
31
|
end
|
33
32
|
|
34
33
|
it "should clear cache when key is destroyed" do
|
35
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
36
|
-
user.customized_attribute(:facebook_email).should eq "kaspernj@facebook.com"
|
37
|
-
|
38
34
|
keys = UserDataKey.where(name: "facebook_email")
|
39
35
|
keys.count.should eq 1
|
40
36
|
keys.destroy_all
|
@@ -46,9 +42,6 @@ describe User do
|
|
46
42
|
end
|
47
43
|
|
48
44
|
it "should update the cache name" do
|
49
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
50
|
-
user.customized_attribute(:facebook_email).should eq "kaspernj@facebook.com"
|
51
|
-
|
52
45
|
key = UserDataKey.where(name: "facebook_email").first
|
53
46
|
key.name = "facebook_mail"
|
54
47
|
key.save!
|
@@ -61,18 +54,14 @@ describe User do
|
|
61
54
|
end
|
62
55
|
|
63
56
|
it "shouldn't allow the same key twice" do
|
64
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
65
57
|
user.customized_attribute(:facebook_email).should eq "kaspernj@facebook.com"
|
66
58
|
|
67
59
|
expect {
|
68
60
|
UserDataKey.create!(name: "facebook_email")
|
69
|
-
}.to raise_error(ActiveRecord::
|
61
|
+
}.to raise_error(ActiveRecord::RecordInvalid)
|
70
62
|
end
|
71
63
|
|
72
64
|
it "shouldn't allow the same data twice" do
|
73
|
-
user.update_customized_attributes(facebook_email: "kaspernj@facebook.com")
|
74
|
-
user.customized_attribute(:facebook_email).should eq "kaspernj@facebook.com"
|
75
|
-
|
76
65
|
expect {
|
77
66
|
UserData.create!(
|
78
67
|
resource_id: user.id,
|
@@ -81,4 +70,21 @@ describe User do
|
|
81
70
|
)
|
82
71
|
}.to raise_error(ActiveRecord::RecordNotUnique)
|
83
72
|
end
|
73
|
+
|
74
|
+
it "should support transactioner" do
|
75
|
+
require "active-record-transactioner"
|
76
|
+
|
77
|
+
ActiveRecordTransactioner.new do |trans|
|
78
|
+
user.update_customized_attributes_with_args(
|
79
|
+
data: {
|
80
|
+
facebook_email: "test@example.com",
|
81
|
+
some_attribute: "test"
|
82
|
+
},
|
83
|
+
transactioner: trans
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
user.customized_attribute(:facebook_email).should eq "test@example.com"
|
88
|
+
user.customized_attribute(:some_attribute).should eq "test"
|
89
|
+
end
|
84
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_customized_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: active-record-transactioner
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Key-based custom attributes that can be created on the fly for ActiveRecord
|
98
112
|
models.
|
99
113
|
email:
|