sentient_user 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .bundle
23
+ vendor
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.2-p320
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sentient_user (0.3.3)
5
+ railties (>= 3.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (3.2.8)
11
+ activemodel (= 3.2.8)
12
+ activesupport (= 3.2.8)
13
+ builder (~> 3.0.0)
14
+ erubis (~> 2.7.0)
15
+ journey (~> 1.0.4)
16
+ rack (~> 1.4.0)
17
+ rack-cache (~> 1.2)
18
+ rack-test (~> 0.6.1)
19
+ sprockets (~> 2.1.3)
20
+ activemodel (3.2.8)
21
+ activesupport (= 3.2.8)
22
+ builder (~> 3.0.0)
23
+ activesupport (3.2.8)
24
+ i18n (~> 0.6)
25
+ multi_json (~> 1.0)
26
+ ansi (1.4.3)
27
+ builder (3.0.4)
28
+ erubis (2.7.0)
29
+ hike (1.2.3)
30
+ i18n (0.6.1)
31
+ journey (1.0.4)
32
+ json (1.7.5)
33
+ minitest (4.7.5)
34
+ minitest_should (0.3.1)
35
+ multi_json (1.3.6)
36
+ rack (1.4.5)
37
+ rack-cache (1.2)
38
+ rack (>= 0.4)
39
+ rack-ssl (1.3.3)
40
+ rack
41
+ rack-test (0.6.2)
42
+ rack (>= 1.0)
43
+ railties (3.2.8)
44
+ actionpack (= 3.2.8)
45
+ activesupport (= 3.2.8)
46
+ rack-ssl (~> 1.3.2)
47
+ rake (>= 0.8.7)
48
+ rdoc (~> 3.4)
49
+ thor (>= 0.14.6, < 2.0)
50
+ rake (0.9.2.2)
51
+ rdoc (3.12)
52
+ json (~> 1.4)
53
+ simplecov (0.6.4)
54
+ multi_json (~> 1.0)
55
+ simplecov-html (~> 0.5.3)
56
+ simplecov-html (0.5.3)
57
+ sprockets (2.1.3)
58
+ hike (~> 1.2)
59
+ rack (~> 1.0)
60
+ tilt (~> 1.1, != 1.3.0)
61
+ thor (0.18.1)
62
+ tilt (1.4.1)
63
+ turn (0.9.6)
64
+ ansi
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ minitest (= 4.7.5)
71
+ minitest_should
72
+ rake
73
+ rdoc
74
+ sentient_user!
75
+ simplecov
76
+ turn
data/README.rdoc CHANGED
@@ -1,11 +1,13 @@
1
1
  = sentient_user
2
2
 
3
- How many times have you needed access to the current user in your models? It happens a lot if you aretrying to do some intelligent logging, if you want the models to control some aspect of their access, and so on. This is easy hackery that you can find in blogs entries all over the web, but I wanted a nice package for it, for eseveral reasons:
3
+ {<img src="https://secure.travis-ci.org/bokmann/sentient_user.png" />}[http://travis-ci.org/bokmann/sentient_user]
4
+
5
+ How often have you needed to access the current user in your models? This happens often if you are attempting intelligent logging or if you want the models to control some aspect of their access, etc. This is easy hackery that you can find in many blog entries, but I wanted a nice package for it, for several reasons:
4
6
 
5
7
  * There are several different ways this can be accomplished, but only the variation that uses Thread.local is safe for use in thread-safe rails.
6
- * Even the Thread.local is considered slightly hacky (but better than monkeypatching ActiveRecord::Base)
7
- * Should fashions change in this area in Rails' future, I want one place to change it, but I want to keep my methods working.
8
- * This concept generally breaks in the console, where there is no controller to set the user. This gem adds a make_current method on the user instance, so you can choose to find a user and execute this method. That could be really useful in rake tasks, for insntance.
8
+ * Even using Thread.local is considered slightly hacky (but better than monkeypatching ActiveRecord::Base)
9
+ * Should fashions change in this area in Rails' future, I want one place to change it, and to keep my methods working.
10
+ * This concept generally breaks in the console, where there is no controller to set the user. This gem adds a make_current method on the user instance, so you can choose to find a user and execute the current_user method. That could be really useful in rake tasks, for instance.
9
11
 
10
12
 
11
13
  == Usage
@@ -17,17 +19,17 @@ include SentientController in your application controller
17
19
  * You have a current_user method available to your controllers
18
20
  * You will write your own tests to cover this code.
19
21
 
20
- If those assumptions don't work for you, feel free to unpack and hack. Its simple enough code to change. I purposefully didn't want to complicate it with an initializer, several config options, etc. as all that would blur this delightfully simple piece of code.
22
+ If those assumptions don't work for you, feel free to unpack and hack. It's simple enough code to change. I purposefully didn't want to complicate it with an initializer, several config options, etc. as all that would blur this delightfully simple piece of code.
21
23
 
22
24
 
23
25
  == Note on Patches/Pull Requests
24
-
26
+
25
27
  * Fork the project.
26
28
  * Make your feature addition or bug fix.
27
- * Add tests for it. This is important so I don't break it in a
28
- future version unintentionally.
29
+ * Add tests for it. This is important so I don't break it
30
+ unintentionally in a future version.
29
31
  * Commit, do not mess with rakefile, version, or history.
30
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
32
+ (if you want to have your own version, that is fine but please bump the version in a commit by itself which I can ignore when I pull)
31
33
  * Send me a pull request. Bonus points for topic branches.
32
34
 
33
35
  == Copyright
data/Rakefile CHANGED
@@ -1,53 +1,15 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "sentient_user"
8
- gem.summary = %Q{A trivial bit of common code}
9
- gem.description = %Q{lets the User model in most authentication frameworks know who is the current user"}
10
- gem.email = "dbock@codesherpas.com"
11
- gem.homepage = "http://github.com/bokmann/sentient_user"
12
- gem.authors = ["bokmann"]
13
- gem.add_development_dependency "shoulda", ">= 2.11.3"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
3
+ require "bundler/gem_tasks"
21
4
  require 'rake/testtask'
5
+
22
6
  Rake::TestTask.new(:test) do |test|
23
7
  test.libs << 'lib' << 'test'
24
8
  test.pattern = 'test/**/test_*.rb'
25
9
  test.verbose = true
26
10
  end
27
11
 
28
- begin
29
- require 'rcov/rcovtask'
30
- Rcov::RcovTask.new do |test|
31
- test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
33
- test.verbose = true
34
- end
35
- rescue LoadError
36
- task :rcov do
37
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
- end
39
- end
40
-
41
- task :test => :check_dependencies
42
-
43
12
  task :default => :test
44
13
 
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
14
 
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "sentient_user #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
15
+ require File.expand_path('../lib/sentient_user/version.rb', __FILE__)
@@ -0,0 +1,3 @@
1
+ module SentientUser
2
+ VERSION = "0.3.3"
3
+ end
@@ -1,52 +1,29 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sentient_user/version.rb', __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{sentient_user}
8
- s.version = "0.3.2"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["bokmann"]
6
+ gem.email = ["dbock@codesherpas.com"]
7
+ gem.description = %q{lets the User model in most authentication frameworks know who is the current user}
8
+ gem.summary = %q{A trivial bit of common code}
9
+ gem.homepage = "http://github.com/bokmann/sentient_user"
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["bokmann"]
12
- s.date = %q{2011-01-17}
13
- s.description = %q{lets the User model in most authentication frameworks know who is the current user"}
14
- s.email = %q{dbock@codesherpas.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/sentient_user.rb",
26
- "sentient_user.gemspec",
27
- "test/helper.rb",
28
- "test/test_sentient_user.rb"
29
- ]
30
- s.homepage = %q{http://github.com/bokmann/sentient_user}
31
- s.require_paths = ["lib"]
32
- s.rubygems_version = %q{1.3.7}
33
- s.summary = %q{A trivial bit of common code}
34
- s.test_files = [
35
- "test/helper.rb",
36
- "test/test_sentient_user.rb"
37
- ]
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "sentient_user"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SentientUser::VERSION
38
17
 
39
- if s.respond_to? :specification_version then
40
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
- s.specification_version = 3
18
+ gem.add_dependency "railties", ">= 3.1"
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "rdoc"
21
+ gem.add_development_dependency "minitest", "4.7.5"
22
+ gem.add_development_dependency 'minitest_should'
23
+ gem.add_development_dependency 'turn'
24
+
25
+ gem.add_development_dependency "simplecov"
42
26
 
43
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
- s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
45
- else
46
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
47
- end
48
- else
49
- s.add_dependency(%q<shoulda>, [">= 2.11.3"])
50
- end
51
27
  end
52
28
 
29
+
data/test/helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'shoulda'
3
+ require "minitest/autorun"
4
+ require "minitest/should"
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -18,3 +19,22 @@ class User
18
19
  end
19
20
 
20
21
  class AnonymousUser < User ; end
22
+
23
+ ExceptedWords = %w{ hackery hacky monkeypatching
24
+ ActiveRecord SentientUser SentientController
25
+ initializer config rakefile bokmann
26
+ sublicense MERCHANTABILITY NONINFRINGEMENT img src
27
+ }
28
+
29
+ def check_spelling_in_file(path_relative_to_gem_root)
30
+ path = "#{File.dirname(__FILE__)}/../#{path_relative_to_gem_root}"
31
+ begin
32
+ aspell_output = `cat #{path} | aspell list`
33
+ rescue => err
34
+ warn "You probably don't have aspell. On mac: brew install aspell --lang=en"
35
+ raise err
36
+ end
37
+ noticed_words = aspell_output.split($/)
38
+ misspellings = noticed_words - ExceptedWords
39
+ assert_equal [], misspellings
40
+ end
@@ -1,28 +1,28 @@
1
1
  require 'helper'
2
2
 
3
- class TestSentientUser < Test::Unit::TestCase
3
+ class TestTruth < Minitest::Should::TestCase
4
4
  should "allow making the 'person' class sentient" do
5
5
  p = Person.new
6
6
  p.make_current
7
7
  assert_equal Person.current, p
8
8
  end
9
-
9
+
10
10
  should "allow making the 'user' class sentient" do
11
11
  u = User.new
12
12
  u.make_current
13
13
  assert_equal User.current, u
14
14
  end
15
-
15
+
16
16
  should "not allow making Person.current a user" do
17
- assert_raise ArgumentError do
17
+ assert_raises ArgumentError do
18
18
  Person.current = User.new
19
19
  end
20
20
  end
21
-
21
+
22
22
  should "allow making person.current a person" do
23
23
  Person.current = Person.new
24
24
  end
25
-
25
+
26
26
  should "allow subclasses of user to be assigned to user.current" do
27
27
  User.current = AnonymousUser.new
28
28
  end
@@ -46,4 +46,12 @@ class TestSentientUser < Test::Unit::TestCase
46
46
  assert_equal Person.current, p
47
47
  end
48
48
  end
49
+
50
+ should "have no spelling errors in its README" do
51
+ check_spelling_in_file "README.rdoc"
52
+ end
53
+
54
+ should "have no spelling errors in the license" do
55
+ check_spelling_in_file "LICENSE"
56
+ end
49
57
  end
metadata CHANGED
@@ -1,92 +1,180 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sentient_user
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - bokmann
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-01-17 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: shoulda
12
+ date: 2013-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
23
55
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
25
65
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 37
30
- segments:
31
- - 2
32
- - 11
33
- - 3
34
- version: 2.11.3
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 4.7.5
35
70
  type: :development
36
- version_requirements: *id001
37
- description: lets the User model in most authentication frameworks know who is the current user"
38
- email: dbock@codesherpas.com
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 4.7.5
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest_should
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
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'
94
+ - !ruby/object:Gem::Dependency
95
+ name: turn
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
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: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: lets the User model in most authentication frameworks know who is the
127
+ current user
128
+ email:
129
+ - dbock@codesherpas.com
39
130
  executables: []
40
-
41
131
  extensions: []
42
-
43
- extra_rdoc_files:
44
- - LICENSE
45
- - README.rdoc
46
- files:
132
+ extra_rdoc_files: []
133
+ files:
47
134
  - .document
135
+ - .gitignore
136
+ - .rbenv-version
137
+ - .travis.yml
138
+ - Gemfile
139
+ - Gemfile.lock
48
140
  - LICENSE
49
141
  - README.rdoc
50
142
  - Rakefile
51
- - VERSION
52
143
  - lib/sentient_user.rb
144
+ - lib/sentient_user/version.rb
53
145
  - sentient_user.gemspec
54
146
  - test/helper.rb
55
147
  - test/test_sentient_user.rb
56
- has_rdoc: true
57
148
  homepage: http://github.com/bokmann/sentient_user
58
149
  licenses: []
59
-
60
150
  post_install_message:
61
151
  rdoc_options: []
62
-
63
- require_paths:
152
+ require_paths:
64
153
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
154
+ required_ruby_version: !ruby/object:Gem::Requirement
66
155
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ segments:
72
161
  - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
162
+ hash: 1916054897882198548
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
164
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ segments:
81
170
  - 0
82
- version: "0"
171
+ hash: 1916054897882198548
83
172
  requirements: []
84
-
85
173
  rubyforge_project:
86
- rubygems_version: 1.3.7
174
+ rubygems_version: 1.8.23
87
175
  signing_key:
88
176
  specification_version: 3
89
177
  summary: A trivial bit of common code
90
- test_files:
178
+ test_files:
91
179
  - test/helper.rb
92
180
  - test/test_sentient_user.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.2