has_scope 0.5.0 → 0.5.1

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.
@@ -0,0 +1,2 @@
1
+ .bundle
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
5
+ gem "rails", "~> 3.0.3"
6
+
7
+ if RUBY_VERSION < "1.9"
8
+ gem "ruby-debug"
9
+ else
10
+ gem "test-unit"
11
+ end
12
+
13
+ gem "mocha"
@@ -35,12 +35,12 @@ Then for each request:
35
35
  /graduations?featured=true
36
36
  #=> calls the named scope and bring featured graduations
37
37
 
38
- /graduations?featured=true&by_degree=phd
39
- #=> brings featured graduations with phd degree
40
-
41
38
  /graduations?params[by_period][started_at]=20100701&params[by_period][ended_at]=20101013
42
39
  #=> brings graduations in the given period
43
40
 
41
+ /graduations?featured=true&by_degree=phd
42
+ #=> brings featured graduations with phd degree
43
+
44
44
  You can retrieve all the scopes applied in one action with <tt>current_scopes</tt> method.
45
45
  In the last case, it would return: { :featured => true, :by_degree => "phd" }.
46
46
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  require 'rake'
3
3
  require 'rake/testtask'
4
- require 'rake/rdoctask'
4
+ require 'rdoc/task'
5
5
 
6
6
  desc 'Default: run unit tests.'
7
7
  task :default => :test
@@ -21,22 +21,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
21
21
  rdoc.options << '--line-numbers' << '--inline-source'
22
22
  rdoc.rdoc_files.include('README.rdoc')
23
23
  rdoc.rdoc_files.include('lib/**/*.rb')
24
- end
25
-
26
- begin
27
- require 'jeweler'
28
- Jeweler::Tasks.new do |s|
29
- s.name = "has_scope"
30
- s.version = "0.5.0"
31
- s.summary = "Maps controller filters to your resource scopes"
32
- s.email = "contact@plataformatec.com.br"
33
- s.homepage = "http://github.com/plataformatec/has_scope"
34
- s.description = "Maps controller filters to your resource scopes"
35
- s.authors = ['José Valim']
36
- s.files = FileList["[A-Z]*", "lib/**/*", "init.rb"]
37
- end
38
-
39
- Jeweler::GemcutterTasks.new
40
- rescue LoadError
41
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
42
- end
24
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "has_scope/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "has_scope"
7
+ s.version = HasScope::VERSION.dup
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "Maps controller filters to your resource scopes."
10
+ s.email = "developers@plataformatec.com.br"
11
+ s.homepage = "http://github.com/plataformatec/has_scope"
12
+ s.description = "Maps controller filters to your resource scopes"
13
+ s.authors = ['José Valim']
14
+
15
+ s.rubyforge_project = "has_scope"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.rdoc_options = ["--charset=UTF-8"]
23
+ s.extra_rdoc_files = [
24
+ "README.rdoc"
25
+ ]
26
+ end
@@ -12,7 +12,7 @@ module HasScope
12
12
  base.class_eval do
13
13
  extend ClassMethods
14
14
  helper_method :current_scopes
15
- class_inheritable_hash :scopes_configuration, :instance_writer => false
15
+ class_attribute :scopes_configuration, :instance_writer => false
16
16
  end
17
17
  end
18
18
 
@@ -58,7 +58,7 @@ module HasScope
58
58
  # end
59
59
  #
60
60
  # has_scope :not_voted_by_me, :type => :boolean do |controller, scope|
61
- # scope.not_voted_by(controller.current_user.id)
61
+ # scope.not_voted_by(controller.current_user.id)
62
62
  # end
63
63
  #
64
64
  def has_scope(*scopes, &block)
@@ -79,11 +79,11 @@ module HasScope
79
79
  options[:only] = Array(options[:only])
80
80
  options[:except] = Array(options[:except])
81
81
 
82
- self.scopes_configuration ||= {}
82
+ self.scopes_configuration = (self.scopes_configuration || {}).dup
83
83
 
84
84
  scopes.each do |scope|
85
85
  self.scopes_configuration[scope] ||= { :as => scope, :type => :default, :block => block }
86
- self.scopes_configuration[scope].merge!(options)
86
+ self.scopes_configuration[scope] = self.scopes_configuration[scope].merge(options)
87
87
  end
88
88
  end
89
89
  end
@@ -0,0 +1,3 @@
1
+ module HasScope
2
+ VERSION = "0.5.1"
3
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class Tree
4
4
  end
@@ -42,12 +42,21 @@ class TreesController < ApplicationController
42
42
  def show_all_colors?
43
43
  false
44
44
  end
45
-
45
+
46
46
  def default_render
47
47
  render :text => action_name
48
48
  end
49
49
  end
50
50
 
51
+ class BonsaisController < TreesController
52
+ has_scope :categories, :if => :categories?
53
+
54
+ protected
55
+ def categories?
56
+ false
57
+ end
58
+ end
59
+
51
60
  class HasScopeTest < ActionController::TestCase
52
61
  tests TreesController
53
62
 
@@ -222,6 +231,11 @@ class HasScopeTest < ActionController::TestCase
222
231
  assert_equal({ :by_category => 'for' }, current_scopes)
223
232
  end
224
233
 
234
+ def test_overwritten_scope
235
+ assert_nil(TreesController.scopes_configuration[:categories][:if])
236
+ assert_equal(:categories?, BonsaisController.scopes_configuration[:categories][:if])
237
+ end
238
+
225
239
  protected
226
240
 
227
241
  def mock_tree(stubs={})
@@ -1,39 +1,31 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
2
3
 
3
- begin
4
- gem "test-unit"
5
- rescue LoadError
6
- end
7
-
8
- begin
9
- gem "ruby-debug"
10
- require 'ruby-debug'
11
- rescue LoadError
12
- end
13
-
4
+ Bundler.setup
14
5
  require 'test/unit'
15
6
  require 'mocha'
16
7
 
8
+ # Configure Rails
17
9
  ENV["RAILS_ENV"] = "test"
18
- RAILS_ROOT = "anywhere"
19
10
 
20
11
  require 'active_support'
21
12
  require 'action_controller'
22
13
  require 'action_dispatch/middleware/flash'
23
14
 
24
- class ApplicationController < ActionController::Base; end
25
-
26
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
15
+ $:.unshift File.expand_path('../../lib', __FILE__)
27
16
  require 'has_scope'
28
17
 
29
- HasScope::Router = ActionDispatch::Routing::RouteSet.new
30
- HasScope::Router.draw do |map|
31
- map.connect ':controller/:action/:id'
32
- map.connect ':controller/:action'
18
+ HasScope::Routes = ActionDispatch::Routing::RouteSet.new
19
+ HasScope::Routes.draw do
20
+ match '/:controller(/:action(/:id))'
21
+ end
22
+
23
+ class ApplicationController < ActionController::Base
24
+ include HasScope::Routes.url_helpers
33
25
  end
34
26
 
35
27
  class ActiveSupport::TestCase
36
28
  setup do
37
- @router = HasScope::Router
29
+ @routes = HasScope::Routes
38
30
  end
39
31
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_scope
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 9
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 5
8
- - 0
9
- version: 0.5.0
9
+ - 1
10
+ version: 0.5.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - "Jos\xC3\xA9 Valim"
@@ -14,12 +15,12 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-03-23 00:00:00 +01:00
18
+ date: 2011-08-02 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: Maps controller filters to your resource scopes
22
- email: contact@plataformatec.com.br
23
+ email: developers@plataformatec.com.br
23
24
  executables: []
24
25
 
25
26
  extensions: []
@@ -27,11 +28,17 @@ extensions: []
27
28
  extra_rdoc_files:
28
29
  - README.rdoc
29
30
  files:
31
+ - .gitignore
32
+ - Gemfile
30
33
  - MIT-LICENSE
31
34
  - README.rdoc
32
35
  - Rakefile
36
+ - has_scope.gemspec
33
37
  - init.rb
34
38
  - lib/has_scope.rb
39
+ - lib/has_scope/version.rb
40
+ - test/has_scope_test.rb
41
+ - test/test_helper.rb
35
42
  has_rdoc: true
36
43
  homepage: http://github.com/plataformatec/has_scope
37
44
  licenses: []
@@ -42,26 +49,30 @@ rdoc_options:
42
49
  require_paths:
43
50
  - lib
44
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
45
53
  requirements:
46
54
  - - ">="
47
55
  - !ruby/object:Gem::Version
56
+ hash: 3
48
57
  segments:
49
58
  - 0
50
59
  version: "0"
51
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
52
62
  requirements:
53
63
  - - ">="
54
64
  - !ruby/object:Gem::Version
65
+ hash: 3
55
66
  segments:
56
67
  - 0
57
68
  version: "0"
58
69
  requirements: []
59
70
 
60
- rubyforge_project:
61
- rubygems_version: 1.3.6
71
+ rubyforge_project: has_scope
72
+ rubygems_version: 1.6.2
62
73
  signing_key:
63
74
  specification_version: 3
64
- summary: Maps controller filters to your resource scopes
75
+ summary: Maps controller filters to your resource scopes.
65
76
  test_files:
66
77
  - test/has_scope_test.rb
67
78
  - test/test_helper.rb