mongoid_userstamp 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rbenv-version +1 -0
- data/.travis.yml +5 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -7
- data/Gemfile.lock +32 -27
- data/README.md +4 -3
- data/Rakefile +10 -1
- data/lib/mongoid/userstamp/user.rb +0 -2
- data/lib/mongoid/userstamp/version.rb +2 -2
- data/lib/mongoid/userstamp.rb +4 -8
- data/mongoid_userstamp.gemspec +21 -22
- data/spec/mongoid/userstamp_spec.rb +62 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/book.rb +7 -0
- data/spec/support/user.rb +7 -0
- metadata +20 -47
- data/.rvmrc +0 -1
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p194
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'mongoid', '
|
3
|
+
gem 'mongoid', '>= 3.0.4'
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem '
|
7
|
-
gem 'yard', '
|
8
|
-
gem 'jeweler', '
|
9
|
-
gem 'magic_encoding', '~> 0.0.2'
|
10
|
-
gem 'whitespace', '~> 2.0.4'
|
6
|
+
gem 'rspec', '>= 2.13.0'
|
7
|
+
gem 'yard', '>= 0.8.2.1'
|
8
|
+
gem 'jeweler', '>= 1.8.3'
|
11
9
|
end
|
12
|
-
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,50 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (3.2.
|
5
|
-
activesupport (= 3.2.
|
4
|
+
activemodel (3.2.13)
|
5
|
+
activesupport (= 3.2.13)
|
6
6
|
builder (~> 3.0.0)
|
7
|
-
activesupport (3.2.
|
8
|
-
i18n (
|
7
|
+
activesupport (3.2.13)
|
8
|
+
i18n (= 0.6.1)
|
9
9
|
multi_json (~> 1.0)
|
10
|
-
builder (3.0.
|
10
|
+
builder (3.0.4)
|
11
|
+
diff-lcs (1.2.1)
|
11
12
|
git (1.2.5)
|
12
|
-
i18n (0.6.
|
13
|
-
jeweler (1.8.
|
13
|
+
i18n (0.6.1)
|
14
|
+
jeweler (1.8.4)
|
14
15
|
bundler (~> 1.0)
|
15
16
|
git (>= 1.2.5)
|
16
17
|
rake
|
17
18
|
rdoc
|
18
|
-
json (1.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
moped (~> 1.1)
|
19
|
+
json (1.7.7)
|
20
|
+
mongoid (3.1.2)
|
21
|
+
activemodel (~> 3.2)
|
22
|
+
moped (~> 1.4.2)
|
23
23
|
origin (~> 1.0)
|
24
24
|
tzinfo (~> 0.3.22)
|
25
|
-
moped (1.
|
26
|
-
multi_json (1.
|
27
|
-
origin (1.0.
|
28
|
-
rake (0.
|
29
|
-
rdoc (
|
25
|
+
moped (1.4.3)
|
26
|
+
multi_json (1.7.1)
|
27
|
+
origin (1.0.11)
|
28
|
+
rake (10.0.3)
|
29
|
+
rdoc (4.0.0)
|
30
30
|
json (~> 1.4)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
rspec (2.13.0)
|
32
|
+
rspec-core (~> 2.13.0)
|
33
|
+
rspec-expectations (~> 2.13.0)
|
34
|
+
rspec-mocks (~> 2.13.0)
|
35
|
+
rspec-core (2.13.1)
|
36
|
+
rspec-expectations (2.13.0)
|
37
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
38
|
+
rspec-mocks (2.13.0)
|
39
|
+
tzinfo (0.3.37)
|
40
|
+
yard (0.8.5.2)
|
35
41
|
|
36
42
|
PLATFORMS
|
37
43
|
ruby
|
44
|
+
x86-mingw32
|
38
45
|
|
39
46
|
DEPENDENCIES
|
40
|
-
jeweler (
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
whitespace (~> 2.0.4)
|
45
|
-
yard (~> 0.8.2.1)
|
47
|
+
jeweler (>= 1.8.3)
|
48
|
+
mongoid (>= 3.0.4)
|
49
|
+
rspec (>= 2.13.0)
|
50
|
+
yard (>= 0.8.2.1)
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
# MongoidUserstamp [![Build Status](https://secure.travis-ci.org/tbpro/mongoid_userstamp.png)](https://
|
1
|
+
# MongoidUserstamp [![Build Status](https://secure.travis-ci.org/tbpro/mongoid_userstamp.png)](https://travis-ci.org/tbpro/mongoid_userstamp) [![Code Climate](https://codeclimate.com/github/tbpro/mongoid_userstamp.png)](https://codeclimate.com/github/tbpro/mongoid_userstamp)
|
2
2
|
|
3
3
|
MongoidUserstamp adds stamp columns for created by and updated by
|
4
|
-
informations within rails applications.
|
4
|
+
informations within rails applications. Mongoid requires a ruby
|
5
|
+
version above 1.8, so i've written the gem on the new 1.9 hash syntax.
|
5
6
|
|
6
7
|
## Install
|
7
8
|
|
@@ -52,4 +53,4 @@ informations within rails applications.
|
|
52
53
|
|
53
54
|
## Credits
|
54
55
|
|
55
|
-
Copyright (c) 2012 Thomas Boerger Programmierung <http://www.tbpro.de>
|
56
|
+
Copyright (c) 2012-2013 Thomas Boerger Programmierung <http://www.tbpro.de>
|
data/Rakefile
CHANGED
@@ -6,6 +6,7 @@ begin
|
|
6
6
|
rescue Bundler::BundlerError => e
|
7
7
|
$stderr.puts e.message
|
8
8
|
$stderr.puts 'Run `bundle install` to install missing gems'
|
9
|
+
|
9
10
|
exit e.status_code
|
10
11
|
end
|
11
12
|
|
@@ -29,4 +30,12 @@ end
|
|
29
30
|
Jeweler::RubygemsDotOrgTasks.new
|
30
31
|
YARD::Rake::YardocTask.new
|
31
32
|
|
32
|
-
|
33
|
+
require 'rspec/core'
|
34
|
+
require 'rspec/core/rake_task'
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
37
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
38
|
+
spec.rspec_opts = '--color --format progress'
|
39
|
+
end
|
40
|
+
|
41
|
+
task default: :spec
|
data/lib/mongoid/userstamp.rb
CHANGED
@@ -9,8 +9,6 @@ module Mongoid
|
|
9
9
|
autoload :User, 'mongoid/userstamp/user'
|
10
10
|
|
11
11
|
included do
|
12
|
-
include Mongoid::Timestamps
|
13
|
-
|
14
12
|
field Mongoid::Userstamp.configuration.updated_column, :type => Object
|
15
13
|
field Mongoid::Userstamp.configuration.created_column, :type => Object
|
16
14
|
|
@@ -18,11 +16,13 @@ module Mongoid
|
|
18
16
|
before_create :set_creator
|
19
17
|
|
20
18
|
define_method Mongoid::Userstamp.configuration.updated_accessor do
|
21
|
-
|
19
|
+
updated_col = self.send(Mongoid::Userstamp.configuration.updated_column)
|
20
|
+
updated_col ? Mongoid::Userstamp.configuration.user_model.find(updated_col) : nil
|
22
21
|
end
|
23
22
|
|
24
23
|
define_method Mongoid::Userstamp.configuration.created_accessor do
|
25
|
-
|
24
|
+
created_col = self.send(Mongoid::Userstamp.configuration.created_column)
|
25
|
+
created_col ? Mongoid::Userstamp.configuration.user_model.find(created_col) : nil
|
26
26
|
end
|
27
27
|
|
28
28
|
protected
|
@@ -42,10 +42,6 @@ module Mongoid
|
|
42
42
|
end
|
43
43
|
|
44
44
|
class << self
|
45
|
-
def configure(&block)
|
46
|
-
@configuration = Mongoid::Userstamp::Config.new(&block)
|
47
|
-
end
|
48
|
-
|
49
45
|
def configuration
|
50
46
|
@configuration ||= Mongoid::Userstamp::Config.new
|
51
47
|
end
|
data/mongoid_userstamp.gemspec
CHANGED
@@ -5,19 +5,20 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mongoid_userstamp"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Thomas Boerger"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-03-24"
|
13
13
|
s.email = "tboerger@tbpro.de"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.md",
|
16
16
|
"README.md"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".
|
19
|
+
".rbenv-version",
|
20
20
|
".travis.yml",
|
21
|
+
"CHANGELOG.md",
|
21
22
|
"Gemfile",
|
22
23
|
"Gemfile.lock",
|
23
24
|
"LICENSE.md",
|
@@ -30,7 +31,11 @@ Gem::Specification.new do |s|
|
|
30
31
|
"lib/mongoid/userstamp/user.rb",
|
31
32
|
"lib/mongoid/userstamp/version.rb",
|
32
33
|
"lib/mongoid_userstamp.rb",
|
33
|
-
"mongoid_userstamp.gemspec"
|
34
|
+
"mongoid_userstamp.gemspec",
|
35
|
+
"spec/mongoid/userstamp_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/support/book.rb",
|
38
|
+
"spec/support/user.rb"
|
34
39
|
]
|
35
40
|
s.homepage = "https://github.com/tbpro/mongoid_userstamp"
|
36
41
|
s.licenses = ["MIT"]
|
@@ -42,27 +47,21 @@ Gem::Specification.new do |s|
|
|
42
47
|
s.specification_version = 3
|
43
48
|
|
44
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
-
s.add_runtime_dependency(%q<mongoid>, ["
|
46
|
-
s.add_development_dependency(%q<
|
47
|
-
s.add_development_dependency(%q<yard>, ["
|
48
|
-
s.add_development_dependency(%q<jeweler>, ["
|
49
|
-
s.add_development_dependency(%q<magic_encoding>, ["~> 0.0.2"])
|
50
|
-
s.add_development_dependency(%q<whitespace>, ["~> 2.0.4"])
|
50
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 3.0.4"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 2.13.0"])
|
52
|
+
s.add_development_dependency(%q<yard>, [">= 0.8.2.1"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
|
51
54
|
else
|
52
|
-
s.add_dependency(%q<mongoid>, ["
|
53
|
-
s.add_dependency(%q<
|
54
|
-
s.add_dependency(%q<yard>, ["
|
55
|
-
s.add_dependency(%q<jeweler>, ["
|
56
|
-
s.add_dependency(%q<magic_encoding>, ["~> 0.0.2"])
|
57
|
-
s.add_dependency(%q<whitespace>, ["~> 2.0.4"])
|
55
|
+
s.add_dependency(%q<mongoid>, [">= 3.0.4"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 2.13.0"])
|
57
|
+
s.add_dependency(%q<yard>, [">= 0.8.2.1"])
|
58
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
58
59
|
end
|
59
60
|
else
|
60
|
-
s.add_dependency(%q<mongoid>, ["
|
61
|
-
s.add_dependency(%q<
|
62
|
-
s.add_dependency(%q<yard>, ["
|
63
|
-
s.add_dependency(%q<jeweler>, ["
|
64
|
-
s.add_dependency(%q<magic_encoding>, ["~> 0.0.2"])
|
65
|
-
s.add_dependency(%q<whitespace>, ["~> 2.0.4"])
|
61
|
+
s.add_dependency(%q<mongoid>, [">= 3.0.4"])
|
62
|
+
s.add_dependency(%q<rspec>, [">= 2.13.0"])
|
63
|
+
s.add_dependency(%q<yard>, [">= 0.8.2.1"])
|
64
|
+
s.add_dependency(%q<jeweler>, [">= 1.8.3"])
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'Mongoid::Userstamp' do
|
5
|
+
subject {
|
6
|
+
Book.new(
|
7
|
+
name: 'Crafting Rails Applications'
|
8
|
+
)
|
9
|
+
}
|
10
|
+
|
11
|
+
it { should respond_to :created_by }
|
12
|
+
it { should respond_to :creator }
|
13
|
+
it { should respond_to :updated_by }
|
14
|
+
it { should respond_to :updator }
|
15
|
+
|
16
|
+
context 'when created without a user' do
|
17
|
+
before {
|
18
|
+
subject.save!
|
19
|
+
}
|
20
|
+
|
21
|
+
it { subject.created_by.should be_nil }
|
22
|
+
it { subject.creator.should be_nil }
|
23
|
+
it { subject.updated_by.should be_nil }
|
24
|
+
it { subject.updator.should be_nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when created by a user' do
|
28
|
+
let(:user_1) {
|
29
|
+
User.create!(
|
30
|
+
name: 'Charles Dikkens'
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
34
|
+
before {
|
35
|
+
User.current = user_1
|
36
|
+
subject.save
|
37
|
+
}
|
38
|
+
|
39
|
+
it { subject.created_by.should == user_1.id }
|
40
|
+
it { subject.creator.should == user_1 }
|
41
|
+
it { subject.updated_by.should == user_1.id }
|
42
|
+
it { subject.updator.should == user_1 }
|
43
|
+
|
44
|
+
context 'when updated by a user' do
|
45
|
+
let(:user_2) {
|
46
|
+
User.create!(
|
47
|
+
name: 'Edmund Wells'
|
48
|
+
)
|
49
|
+
}
|
50
|
+
|
51
|
+
before {
|
52
|
+
User.current = user_2
|
53
|
+
subject.save!
|
54
|
+
}
|
55
|
+
|
56
|
+
it { subject.created_by.should == user_1.id }
|
57
|
+
it { subject.creator.should == user_1 }
|
58
|
+
it { subject.updated_by.should == user_2.id }
|
59
|
+
it { subject.updator.should == user_2 }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
5
|
+
|
6
|
+
require 'active_support/all'
|
7
|
+
require 'mongoid'
|
8
|
+
require 'mongoid_userstamp'
|
9
|
+
|
10
|
+
Mongoid.configure do |config|
|
11
|
+
config.connect_to(
|
12
|
+
'mongoid_userstamp_test'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |f|
|
17
|
+
require f
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.mock_with :rspec
|
22
|
+
|
23
|
+
config.after :suite do
|
24
|
+
Mongoid.purge!
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_userstamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,14 +9,14 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 3.0.4
|
22
22
|
type: :runtime
|
@@ -24,31 +24,31 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 3.0.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 2.
|
37
|
+
version: 2.13.0
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 2.
|
45
|
+
version: 2.13.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: yard
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: 0.8.2.1
|
54
54
|
type: :development
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.2.1
|
62
62
|
- !ruby/object:Gem::Dependency
|
@@ -64,7 +64,7 @@ dependencies:
|
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: 1.8.3
|
70
70
|
type: :development
|
@@ -72,41 +72,9 @@ dependencies:
|
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.8.3
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: magic_encoding
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 0.0.2
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 0.0.2
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: whitespace
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 2.0.4
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ~>
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 2.0.4
|
110
78
|
description:
|
111
79
|
email: tboerger@tbpro.de
|
112
80
|
executables: []
|
@@ -115,8 +83,9 @@ extra_rdoc_files:
|
|
115
83
|
- LICENSE.md
|
116
84
|
- README.md
|
117
85
|
files:
|
118
|
-
- .
|
86
|
+
- .rbenv-version
|
119
87
|
- .travis.yml
|
88
|
+
- CHANGELOG.md
|
120
89
|
- Gemfile
|
121
90
|
- Gemfile.lock
|
122
91
|
- LICENSE.md
|
@@ -130,6 +99,10 @@ files:
|
|
130
99
|
- lib/mongoid/userstamp/version.rb
|
131
100
|
- lib/mongoid_userstamp.rb
|
132
101
|
- mongoid_userstamp.gemspec
|
102
|
+
- spec/mongoid/userstamp_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- spec/support/book.rb
|
105
|
+
- spec/support/user.rb
|
133
106
|
homepage: https://github.com/tbpro/mongoid_userstamp
|
134
107
|
licenses:
|
135
108
|
- MIT
|
@@ -145,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
118
|
version: '0'
|
146
119
|
segments:
|
147
120
|
- 0
|
148
|
-
hash:
|
121
|
+
hash: 4199627598995250851
|
149
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
123
|
none: false
|
151
124
|
requirements:
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use ruby-1.9.3-p194@mongoid_userstamp --create
|