exposable_attributes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/exposable_attributes/version.rb +1 -1
- data/test/exposable_attributes_test.rb +62 -2
- data/test/test_helper.rb +21 -0
- metadata +4 -3
@@ -1,8 +1,68 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
# base
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
end
|
6
|
+
|
7
|
+
class User1 < User
|
8
|
+
exposable_attributes :xml, :except => [:encrypted_password]
|
9
|
+
exposable_attributes :json, :only => [:login]
|
10
|
+
end
|
11
|
+
|
12
|
+
class User2 < User
|
13
|
+
exposable_attributes :id, :login
|
14
|
+
end
|
15
|
+
|
3
16
|
class ExposableAttributesTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
17
|
+
|
18
|
+
setup_db
|
19
|
+
|
20
|
+
test "Four users should be created after db setup" do
|
21
|
+
assert_equal 4, User.count
|
22
|
+
end
|
23
|
+
|
24
|
+
test "User1#to_json should not expose anything except login" do
|
25
|
+
json = User1.first.to_json
|
26
|
+
assert_match /login/, json
|
27
|
+
|
28
|
+
assert_no_match /id/, json
|
29
|
+
assert_no_match /salt/, json
|
30
|
+
assert_no_match /encrypted.password/, json
|
31
|
+
end
|
32
|
+
|
33
|
+
test "User1#to_xml should not expose encrypted_password" do
|
34
|
+
xml = User1.first.to_xml
|
35
|
+
|
36
|
+
assert_no_match /encrypted.password/, xml
|
37
|
+
|
38
|
+
assert_match /id/, xml
|
39
|
+
assert_match /login/, xml
|
40
|
+
assert_match /salt/, xml
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
test "User2#to_xml and to_json should expose id and login only" do
|
45
|
+
xml = User2.first.to_xml
|
46
|
+
json = User2.last.to_json
|
47
|
+
|
48
|
+
for serialized in [xml, json] do
|
49
|
+
assert_match /id/, serialized
|
50
|
+
assert_match /login/, serialized
|
51
|
+
assert_no_match /salt/, serialized
|
52
|
+
assert_no_match /encrypted.password/, serialized
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test "Ensure that User#to_xml and User#to_json are not affected" do
|
57
|
+
xml = User.first.to_xml
|
58
|
+
json = User.last.to_json
|
59
|
+
|
60
|
+
for serialized in [xml, json] do
|
61
|
+
assert_match /id/, serialized
|
62
|
+
assert_match /login/, serialized
|
63
|
+
assert_match /salt/, serialized
|
64
|
+
assert_match /encrypted.password/, serialized
|
65
|
+
end
|
6
66
|
end
|
7
67
|
|
8
68
|
end
|
data/test/test_helper.rb
CHANGED
@@ -4,3 +4,24 @@ require 'active_support'
|
|
4
4
|
require 'active_support/test_case'
|
5
5
|
require 'active_record'
|
6
6
|
require 'active_record/fixtures'
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), '../rails/init')
|
9
|
+
|
10
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
11
|
+
|
12
|
+
def setup_db
|
13
|
+
ActiveRecord::Schema.define(:version => 1) do
|
14
|
+
create_table :users do |t|
|
15
|
+
t.string :login
|
16
|
+
t.string :encrypted_password
|
17
|
+
t.string :salt
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
4.times do |i|
|
22
|
+
User.create!(:login => "anonymous-#{i}",
|
23
|
+
:encrypted_password => "password-#{i}",
|
24
|
+
:salt => "#{i ^ 65534}")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
metadata
CHANGED
@@ -5,16 +5,17 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrey Nikolaev
|
13
|
+
- Maxim Filatov
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-08 00:00:00 +04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|