mongoid-userstamps 3.1.3 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +9 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +12 -4
- data/Rakefile +9 -10
- data/init.rb +1 -2
- data/lib/mongoid-userstamps.rb +1 -4
- data/lib/mongoid/userstamps.rb +8 -11
- data/lib/mongoid/userstamps/config.rb +9 -15
- data/lib/mongoid/userstamps/config/model.rb +12 -6
- data/lib/mongoid/userstamps/config/user.rb +0 -3
- data/lib/mongoid/userstamps/created.rb +4 -7
- data/lib/mongoid/userstamps/deleted.rb +4 -7
- data/lib/mongoid/userstamps/model.rb +0 -1
- data/lib/mongoid/userstamps/railtie.rb +0 -3
- data/lib/mongoid/userstamps/updated.rb +4 -7
- data/lib/mongoid/userstamps/user.rb +2 -4
- data/lib/mongoid/userstamps/version.rb +1 -4
- data/mongoid-userstamps.gemspec +17 -19
- data/spec/spec_helper.rb +9 -10
- data/spec/support/admin.rb +1 -2
- data/spec/support/book.rb +2 -3
- data/spec/support/post.rb +2 -3
- data/spec/support/user.rb +0 -1
- data/spec/unit/gem_config_spec.rb +8 -11
- data/spec/unit/model_config_spec.rb +15 -14
- data/spec/unit/model_spec.rb +41 -36
- data/spec/unit/user_config_spec.rb +5 -8
- data/spec/unit/user_spec.rb +38 -34
- data/spec/unit/userstamp_spec.rb +48 -51
- data/test/config_test.rb +13 -10
- data/test/model_test.rb +12 -13
- data/test/models/archive.rb +0 -1
- data/test/models/comment.rb +1 -2
- data/test/models/person.rb +0 -1
- data/test/models/post.rb +1 -2
- data/test/models/user.rb +0 -1
- data/test/paranoia_test.rb +2 -3
- data/test/test_helper.rb +9 -8
- data/test/user_test.rb +9 -10
- metadata +7 -6
data/spec/support/admin.rb
CHANGED
data/spec/support/book.rb
CHANGED
data/spec/support/post.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# -*- encoding : utf-8 -*-
|
2
1
|
class Post
|
3
2
|
include Mongoid::Document
|
4
3
|
include Mongoid::Userstamp
|
5
4
|
|
6
|
-
mongoid_userstamp user_model:
|
5
|
+
mongoid_userstamp user_model: "Admin",
|
7
6
|
created_name: :writer,
|
8
7
|
updated_name: :editor
|
9
8
|
|
10
9
|
field :title
|
11
|
-
end
|
10
|
+
end
|
data/spec/support/user.rb
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp::GemConfig do
|
5
|
-
|
6
4
|
subject { Mongoid::Userstamp::GemConfig.new }
|
7
5
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
context 'without block' do
|
6
|
+
describe "#initialize" do
|
7
|
+
context "without block" do
|
11
8
|
it { should be_a Mongoid::Userstamp::GemConfig }
|
12
9
|
it { subject.created_name.should eq :created_by }
|
13
10
|
it { subject.updated_name.should eq :updated_by }
|
14
11
|
it { subject.user_reader.should eq :current_user }
|
15
12
|
end
|
16
13
|
|
17
|
-
context
|
14
|
+
context "with block" do
|
18
15
|
subject do
|
19
16
|
Mongoid::Userstamp::GemConfig.new do |u|
|
20
|
-
u.created_name
|
21
|
-
u.updated_name
|
17
|
+
u.created_name = :c_by
|
18
|
+
u.updated_name = :u_by
|
22
19
|
u.user_reader = :foo
|
23
20
|
end
|
24
21
|
end
|
@@ -30,7 +27,7 @@ describe Mongoid::Userstamp::GemConfig do
|
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
|
-
describe
|
30
|
+
describe "deprecated methods" do
|
34
31
|
subject do
|
35
32
|
Mongoid::Userstamp::GemConfig.new do |u|
|
36
33
|
u.user_model = :bar
|
@@ -38,7 +35,7 @@ describe Mongoid::Userstamp::GemConfig do
|
|
38
35
|
u.updated_column = :baz
|
39
36
|
end
|
40
37
|
end
|
41
|
-
it { ->{ subject }.should_not raise_error }
|
38
|
+
it { -> { subject }.should_not raise_error }
|
42
39
|
it { should be_a Mongoid::Userstamp::GemConfig }
|
43
40
|
it { subject.created_name.should eq :bing }
|
44
41
|
it { subject.updated_name.should eq :baz }
|
@@ -1,19 +1,20 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp::ModelConfig do
|
5
|
-
|
6
4
|
subject { Mongoid::Userstamp::ModelConfig.new }
|
7
|
-
before
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
before do
|
6
|
+
Mongoid::Userstamp.stub("config").and_return(OpenStruct.new(created_name: :created_by,
|
7
|
+
updated_name: :updated_by))
|
8
|
+
end
|
9
|
+
before { Mongoid::Userstamp.stub("user_classes").and_return(["User"]) }
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
describe "#initialize" do
|
12
|
+
context "with opts hash" do
|
13
|
+
subject {
|
14
|
+
Mongoid::Userstamp::ModelConfig.new(user_model: :bar,
|
15
|
+
created_name: :c_by,
|
16
|
+
updated_name: :u_by)
|
17
|
+
}
|
17
18
|
|
18
19
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
19
20
|
it { subject.user_model.should eq :bar }
|
@@ -21,9 +22,9 @@ describe Mongoid::Userstamp::ModelConfig do
|
|
21
22
|
it { subject.updated_name.should eq :u_by }
|
22
23
|
end
|
23
24
|
|
24
|
-
context
|
25
|
+
context "without opts hash" do
|
25
26
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
26
|
-
it { subject.user_model.should eq
|
27
|
+
it { subject.user_model.should eq "User" }
|
27
28
|
it { subject.created_name.should eq :created_by }
|
28
29
|
it { subject.updated_name.should eq :updated_by }
|
29
30
|
end
|
data/spec/unit/model_spec.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp::Model do
|
4
|
+
subject(:book) { Book.new(name: "Crafting Rails Applications") }
|
5
|
+
subject(:post) { Post.new(title: "Understanding Rails") }
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
let(:user_1) { User.create!(name: "Charles Dikkens") }
|
8
|
+
let(:user_2) { User.create!(name: "Edmund Wells") }
|
9
|
+
let(:admin_1) { Admin.create!(name: "JK Rowling") }
|
10
|
+
let(:admin_2) { Admin.create!(name: "Stephan Norway") }
|
8
11
|
|
9
|
-
|
10
|
-
let(:user_2) { User.create!(name: 'Edmund Wells') }
|
11
|
-
let(:admin_1) { Admin.create!(name: 'JK Rowling') }
|
12
|
-
let(:admin_2) { Admin.create!(name: 'Stephan Norway') }
|
13
|
-
|
14
|
-
describe '::mongoid_userstamp_config' do
|
12
|
+
describe "::mongoid_userstamp_config" do
|
15
13
|
before do
|
16
14
|
@config = Book.instance_variable_get(:'@mongoid_userstamp_config')
|
17
15
|
Book.instance_variable_set(:'@mongoid_userstamp_config', nil)
|
@@ -21,64 +19,71 @@ describe Mongoid::Userstamp::Model do
|
|
21
19
|
Book.instance_variable_set(:'@mongoid_userstamp_config', @config)
|
22
20
|
end
|
23
21
|
|
24
|
-
context
|
25
|
-
subject{ Book.mongoid_userstamp_config }
|
22
|
+
context "when options are not given" do
|
23
|
+
subject { Book.mongoid_userstamp_config }
|
26
24
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
27
25
|
it { subject.user_model.should eq Admin }
|
28
26
|
it { subject.created_name.should eq :created_by }
|
29
27
|
it { subject.updated_name.should eq :updated_by }
|
30
28
|
end
|
31
29
|
|
32
|
-
context
|
33
|
-
subject{ Book.mongoid_userstamp_config(user_model:
|
30
|
+
context "when options are given" do
|
31
|
+
subject { Book.mongoid_userstamp_config(user_model: "User", created_name: :foo, updated_name: :bar) }
|
34
32
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
35
|
-
it { subject.user_model.should eq
|
33
|
+
it { subject.user_model.should eq "User" }
|
36
34
|
it { subject.created_name.should eq :foo }
|
37
35
|
it { subject.updated_name.should eq :bar }
|
38
36
|
end
|
39
37
|
|
40
|
-
context
|
41
|
-
subject
|
38
|
+
context "when mongoid_userstamp_user has been set" do
|
39
|
+
subject do
|
40
|
+
Book.mongoid_userstamp_config
|
41
|
+
Book.mongoid_userstamp_config(user_model: "User", created_name: :foo, updated_name: :bar)
|
42
|
+
end
|
42
43
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
43
44
|
it { subject.user_model.should eq Admin }
|
44
45
|
it { subject.created_name.should eq :created_by }
|
45
46
|
it { subject.updated_name.should eq :updated_by }
|
46
47
|
end
|
47
48
|
|
48
|
-
context
|
49
|
-
subject
|
49
|
+
context "when set via mongoid_userstamp method" do
|
50
|
+
subject do
|
51
|
+
Book.mongoid_userstamp(user_model: "User", created_name: :foo, updated_name: :bar)
|
52
|
+
Book.mongoid_userstamp_config
|
53
|
+
end
|
50
54
|
it { should be_a Mongoid::Userstamp::ModelConfig }
|
51
|
-
it { subject.user_model.should eq
|
55
|
+
it { subject.user_model.should eq "User" }
|
52
56
|
it { subject.created_name.should eq :foo }
|
53
57
|
it { subject.updated_name.should eq :bar }
|
54
58
|
end
|
55
59
|
end
|
56
60
|
|
57
|
-
describe
|
58
|
-
|
59
|
-
|
61
|
+
describe "::current_user" do
|
62
|
+
before do
|
63
|
+
Admin.current = nil
|
64
|
+
User.current = nil
|
65
|
+
end
|
60
66
|
|
61
|
-
context
|
67
|
+
context "when current book user is not set" do
|
62
68
|
it { Book.current_user.should be_nil }
|
63
69
|
it { Post.current_user.should be_nil }
|
64
70
|
end
|
65
71
|
|
66
|
-
context
|
67
|
-
before{ User.current = user_1 }
|
72
|
+
context "when current book user is set" do
|
73
|
+
before { User.current = user_1 }
|
68
74
|
it { Book.current_user.should eq user_1 }
|
69
75
|
it { Post.current_user.should be_nil }
|
70
76
|
end
|
71
77
|
|
72
|
-
context
|
73
|
-
before{ Admin.current = admin_1 }
|
78
|
+
context "when current post user is set" do
|
79
|
+
before { Admin.current = admin_1 }
|
74
80
|
it { Book.current_user.should be_nil }
|
75
81
|
it { Post.current_user.should eq admin_1 }
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
79
|
-
describe
|
80
|
-
|
81
|
-
context 'when created without a user' do
|
85
|
+
describe "relations and callbacks" do
|
86
|
+
context "when created without a user" do
|
82
87
|
before do
|
83
88
|
User.current = nil
|
84
89
|
Admin.current = nil
|
@@ -92,7 +97,7 @@ describe Mongoid::Userstamp::Model do
|
|
92
97
|
it { post.editor.should be_nil }
|
93
98
|
end
|
94
99
|
|
95
|
-
context
|
100
|
+
context "when created with a user" do
|
96
101
|
before do
|
97
102
|
User.current = user_1
|
98
103
|
Admin.current = admin_1
|
@@ -106,7 +111,7 @@ describe Mongoid::Userstamp::Model do
|
|
106
111
|
it { post.editor.should eq admin_1 }
|
107
112
|
end
|
108
113
|
|
109
|
-
context
|
114
|
+
context "when creator is manually set" do
|
110
115
|
before do
|
111
116
|
User.current = user_1
|
112
117
|
Admin.current = admin_1
|
@@ -122,7 +127,7 @@ describe Mongoid::Userstamp::Model do
|
|
122
127
|
it { post.editor.should eq admin_1 }
|
123
128
|
end
|
124
129
|
|
125
|
-
context
|
130
|
+
context "when updater is manually set" do
|
126
131
|
before do
|
127
132
|
User.current = user_1
|
128
133
|
Admin.current = admin_1
|
@@ -138,7 +143,7 @@ describe Mongoid::Userstamp::Model do
|
|
138
143
|
it { post.editor.should eq admin_2 }
|
139
144
|
end
|
140
145
|
|
141
|
-
context
|
146
|
+
context "when user has been destroyed" do
|
142
147
|
before do
|
143
148
|
User.current = user_1
|
144
149
|
Admin.current = admin_1
|
@@ -154,4 +159,4 @@ describe Mongoid::Userstamp::Model do
|
|
154
159
|
it { Post.first.editor.should be_nil }
|
155
160
|
end
|
156
161
|
end
|
157
|
-
end
|
162
|
+
end
|
@@ -1,21 +1,18 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp::UserConfig do
|
5
|
-
|
6
4
|
subject { Mongoid::Userstamp::UserConfig.new }
|
7
|
-
before
|
8
|
-
|
9
|
-
describe '#initialize' do
|
5
|
+
before { Mongoid::Userstamp.stub("config").and_return(OpenStruct.new(user_reader: :foo)) }
|
10
6
|
|
11
|
-
|
7
|
+
describe "#initialize" do
|
8
|
+
context "with opts hash" do
|
12
9
|
subject { Mongoid::Userstamp::UserConfig.new({reader: :bar}) }
|
13
10
|
|
14
11
|
it { should be_a Mongoid::Userstamp::UserConfig }
|
15
12
|
it { subject.reader.should eq :bar }
|
16
13
|
end
|
17
14
|
|
18
|
-
context
|
15
|
+
context "without opts hash" do
|
19
16
|
it { should be_a Mongoid::Userstamp::UserConfig }
|
20
17
|
it { subject.reader.should eq :foo }
|
21
18
|
end
|
data/spec/unit/user_spec.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp::User do
|
4
|
+
subject(:book) { Book.new(name: "Crafting Rails Applications") }
|
5
|
+
subject(:post) { Post.new(title: "Understanding Rails") }
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
let(:user_1) { User.create!(name: "Charles Dikkens") }
|
8
|
+
let(:user_2) { User.create!(name: "Edmund Wells") }
|
9
|
+
let(:admin_1) { Admin.create!(name: "JK Rowling") }
|
10
|
+
let(:admin_2) { Admin.create!(name: "Stephan Norway") }
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
describe '::current and #current?' do
|
15
|
-
before { Admin.current = nil; User.current = nil }
|
12
|
+
describe "::current and #current?" do
|
13
|
+
before do
|
14
|
+
Admin.current = nil
|
15
|
+
User.current = nil
|
16
|
+
end
|
16
17
|
|
17
|
-
context
|
18
|
+
context "when current users are not set" do
|
18
19
|
it { Admin.current.should be_nil }
|
19
20
|
it { User.current.should be_nil }
|
20
21
|
it { admin_1.current?.should be_falsey }
|
@@ -23,8 +24,8 @@ describe Mongoid::Userstamp::User do
|
|
23
24
|
it { user_2.current?.should be_falsey }
|
24
25
|
end
|
25
26
|
|
26
|
-
context
|
27
|
-
before{ User.current = user_1 }
|
27
|
+
context "when current User is set" do
|
28
|
+
before { User.current = user_1 }
|
28
29
|
it { User.current.should eq user_1 }
|
29
30
|
it { Admin.current.should be_nil }
|
30
31
|
it { admin_1.current?.should be_falsey }
|
@@ -33,8 +34,8 @@ describe Mongoid::Userstamp::User do
|
|
33
34
|
it { user_2.current?.should be_falsey }
|
34
35
|
end
|
35
36
|
|
36
|
-
context
|
37
|
-
before{ Admin.current = admin_1 }
|
37
|
+
context "when current Admin is set" do
|
38
|
+
before { Admin.current = admin_1 }
|
38
39
|
it { User.current.should be_nil }
|
39
40
|
it { Admin.current.should eq admin_1 }
|
40
41
|
it { admin_1.current?.should be_truthy }
|
@@ -44,8 +45,8 @@ describe Mongoid::Userstamp::User do
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
|
-
describe
|
48
|
-
it
|
48
|
+
describe "::do_as" do
|
49
|
+
it "should set the current user" do
|
49
50
|
Admin.current = admin_1
|
50
51
|
Admin.do_as admin_2 do
|
51
52
|
Admin.current.should eq admin_2
|
@@ -53,13 +54,13 @@ describe Mongoid::Userstamp::User do
|
|
53
54
|
Admin.current.should eq admin_1
|
54
55
|
end
|
55
56
|
|
56
|
-
it
|
57
|
-
Admin.do_as admin_2
|
58
|
-
|
59
|
-
|
57
|
+
it "should return the value of the block" do
|
58
|
+
Admin.do_as admin_2 {
|
59
|
+
"foo"
|
60
|
+
}.should eq "foo"
|
60
61
|
end
|
61
62
|
|
62
|
-
it
|
63
|
+
it "should revert user in case of error" do
|
63
64
|
Admin.current = admin_1
|
64
65
|
begin
|
65
66
|
Admin.do_as admin_2 do
|
@@ -71,25 +72,28 @@ describe Mongoid::Userstamp::User do
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
describe
|
75
|
-
before{ User.instance_variable_set(:'@mongoid_userstamp_user', nil) }
|
75
|
+
describe "::mongoid_userstamp_user" do
|
76
|
+
before { User.instance_variable_set(:'@mongoid_userstamp_user', nil) }
|
76
77
|
|
77
|
-
context
|
78
|
-
subject{ User.mongoid_userstamp_user }
|
78
|
+
context "when options are not given" do
|
79
|
+
subject { User.mongoid_userstamp_user }
|
79
80
|
it { should be_a Mongoid::Userstamp::UserConfig }
|
80
|
-
it { subject.reader.should eq :current_user
|
81
|
+
it { subject.reader.should eq :current_user }
|
81
82
|
end
|
82
83
|
|
83
|
-
context
|
84
|
-
subject{ User.mongoid_userstamp_user(reader: :foo) }
|
84
|
+
context "when options are given" do
|
85
|
+
subject { User.mongoid_userstamp_user(reader: :foo) }
|
85
86
|
it { should be_a Mongoid::Userstamp::UserConfig }
|
86
|
-
it { subject.reader.should eq :foo
|
87
|
+
it { subject.reader.should eq :foo }
|
87
88
|
end
|
88
89
|
|
89
|
-
context
|
90
|
-
subject
|
90
|
+
context "when mongoid_userstamp_user has been set" do
|
91
|
+
subject do
|
92
|
+
User.mongoid_userstamp_user
|
93
|
+
User.mongoid_userstamp_user(reader: :foo)
|
94
|
+
end
|
91
95
|
it { should be_a Mongoid::Userstamp::UserConfig }
|
92
|
-
it { subject.reader.should eq :current_user
|
96
|
+
it { subject.reader.should eq :current_user }
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|
data/spec/unit/userstamp_spec.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Mongoid::Userstamp do
|
4
|
+
subject { Mongoid::Userstamp }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
let(:
|
9
|
-
let(:user_2){ User.create!(name: 'Charles Dikkens') }
|
10
|
-
let(:admin_1){ Admin.create!(name: 'JK Rowling') }
|
11
|
-
|
12
|
-
describe '#config' do
|
6
|
+
let(:user_1) { User.create!(name: "Edmund Wells") }
|
7
|
+
let(:user_2) { User.create!(name: "Charles Dikkens") }
|
8
|
+
let(:admin_1) { Admin.create!(name: "JK Rowling") }
|
13
9
|
|
10
|
+
describe "#config" do
|
14
11
|
before { Mongoid::Userstamp.instance_variable_set(:'@config', nil) }
|
15
12
|
|
16
|
-
context
|
17
|
-
subject{ Mongoid::Userstamp.config }
|
13
|
+
context "without block" do
|
14
|
+
subject { Mongoid::Userstamp.config }
|
18
15
|
it { should be_a Mongoid::Userstamp::GemConfig }
|
19
16
|
it { subject.created_name.should eq :created_by }
|
20
17
|
it { subject.updated_name.should eq :updated_by }
|
21
18
|
it { subject.user_reader.should eq :current_user }
|
22
19
|
end
|
23
20
|
|
24
|
-
context
|
21
|
+
context "with block" do
|
25
22
|
subject do
|
26
23
|
Mongoid::Userstamp.config do |u|
|
27
24
|
u.created_name = :c_by
|
@@ -35,87 +32,87 @@ describe Mongoid::Userstamp do
|
|
35
32
|
it { subject.user_reader.should eq :foo }
|
36
33
|
end
|
37
34
|
|
38
|
-
context
|
39
|
-
subject{ Mongoid::Userstamp.configure }
|
35
|
+
context "deprecated method" do
|
36
|
+
subject { Mongoid::Userstamp.configure }
|
40
37
|
it { should be_a Mongoid::Userstamp::GemConfig }
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
44
|
-
describe
|
41
|
+
describe "#current_user" do
|
45
42
|
before do
|
46
43
|
Mongoid::Userstamp.set_current_user(user_1)
|
47
44
|
Mongoid::Userstamp.set_current_user(admin_1)
|
48
45
|
end
|
49
|
-
context
|
50
|
-
subject{ Mongoid::Userstamp.current_user(
|
51
|
-
it{ should eq user_1 }
|
46
|
+
context "when user_class is User" do
|
47
|
+
subject { Mongoid::Userstamp.current_user("User") }
|
48
|
+
it { should eq user_1 }
|
52
49
|
end
|
53
|
-
context
|
54
|
-
subject{ Mongoid::Userstamp.current_user(
|
55
|
-
it{ should eq admin_1 }
|
50
|
+
context "when user_class is Admin" do
|
51
|
+
subject { Mongoid::Userstamp.current_user("Admin") }
|
52
|
+
it { should eq admin_1 }
|
56
53
|
end
|
57
|
-
context
|
58
|
-
subject{ Mongoid::Userstamp.current_user(
|
59
|
-
it{ should be_nil }
|
54
|
+
context "when user_class is other" do
|
55
|
+
subject { Mongoid::Userstamp.current_user("foobar") }
|
56
|
+
it { should be_nil }
|
60
57
|
end
|
61
|
-
context
|
62
|
-
subject{ Mongoid::Userstamp.current_user }
|
63
|
-
it
|
58
|
+
context "when user_class is not given" do
|
59
|
+
subject { Mongoid::Userstamp.current_user }
|
60
|
+
it "should use the default user_class" do
|
64
61
|
should eq admin_1
|
65
62
|
end
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
|
-
describe
|
66
|
+
describe "#model_classes" do
|
70
67
|
before { Mongoid::Userstamp.instance_variable_set(:'@model_classes', nil) }
|
71
|
-
context
|
68
|
+
context "default value" do
|
72
69
|
it { subject.model_classes.should eq [] }
|
73
70
|
end
|
74
|
-
context
|
71
|
+
context "setting values" do
|
75
72
|
before do
|
76
|
-
subject.add_model_class
|
77
|
-
subject.add_model_class
|
73
|
+
subject.add_model_class "Book"
|
74
|
+
subject.add_model_class "Post"
|
78
75
|
end
|
79
76
|
it { subject.model_classes.should eq [Book, Post] }
|
80
77
|
end
|
81
78
|
end
|
82
79
|
|
83
|
-
describe
|
80
|
+
describe "#user_classes" do
|
84
81
|
before { Mongoid::Userstamp.instance_variable_set(:'@user_classes', nil) }
|
85
|
-
context
|
82
|
+
context "default value" do
|
86
83
|
it { subject.user_classes.should eq [] }
|
87
84
|
end
|
88
|
-
context
|
85
|
+
context "setting values" do
|
89
86
|
before do
|
90
|
-
subject.add_user_class
|
91
|
-
subject.add_user_class
|
87
|
+
subject.add_user_class "Book"
|
88
|
+
subject.add_user_class "Post"
|
92
89
|
end
|
93
90
|
it { subject.user_classes.should eq [Book, Post] }
|
94
91
|
end
|
95
92
|
end
|
96
93
|
|
97
|
-
describe
|
98
|
-
context
|
94
|
+
describe "#store" do
|
95
|
+
context "when RequestStore is defined" do
|
99
96
|
before do
|
100
|
-
stub_const(
|
101
|
-
RequestStore.stub(
|
97
|
+
stub_const("RequestStore", Object.new)
|
98
|
+
RequestStore.stub("store").and_return("foobar")
|
102
99
|
end
|
103
100
|
it { subject.store.should eq RequestStore.store }
|
104
101
|
end
|
105
|
-
context
|
106
|
-
before{ hide_const(
|
102
|
+
context "when RequestStore is not defined" do
|
103
|
+
before { hide_const("RequestStore") }
|
107
104
|
it { subject.store.should eq Thread.current }
|
108
105
|
end
|
109
106
|
end
|
110
107
|
|
111
|
-
describe
|
112
|
-
context
|
113
|
-
subject{ Mongoid::Userstamp.userstamp_key(User) }
|
114
|
-
it{ should eq :"mongoid_userstamp/user" }
|
115
|
-
end
|
116
|
-
context
|
117
|
-
subject{ Mongoid::Userstamp.userstamp_key(
|
118
|
-
it{ should eq :"mongoid_userstamp/my_namespace/user" }
|
108
|
+
describe "#userstamp_key" do
|
109
|
+
context "when model is a Class" do
|
110
|
+
subject { Mongoid::Userstamp.userstamp_key(User) }
|
111
|
+
it { should eq :"mongoid_userstamp/user" }
|
112
|
+
end
|
113
|
+
context "when model is a String" do
|
114
|
+
subject { Mongoid::Userstamp.userstamp_key("MyNamespace::User") }
|
115
|
+
it { should eq :"mongoid_userstamp/my_namespace/user" }
|
119
116
|
end
|
120
117
|
end
|
121
118
|
end
|