validation_scopes 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.4.1 2012-04-15
2
+
3
+ * Rails 3.1 and 3.2 compatibility
4
+ * Added the method all_scopes that return all the scopes in a model
5
+
1
6
  == 0.4.0 2011-05-23
2
7
 
3
8
  * Fixed problem with #model_name on proxy class (dynamic_form plugin)
data/README.md CHANGED
@@ -46,6 +46,9 @@ previous example:
46
46
  film.errors.full_messages
47
47
  => []
48
48
 
49
+ film.class.all_scopes
50
+ => [:warnings]
51
+
49
52
  film.save
50
53
  => true
51
54
 
@@ -57,7 +60,11 @@ does not accept an `ActiveRecord::Errors` object directly. Instead you need to
57
60
 
58
61
  ## Compatibility
59
62
 
60
- Should work for Ruby 1.8 and 1.9, as well as Rails 2.x and 3.x; Battle-tested in the formers.
63
+ The current version should work for Rails 3 on Ruby 1.8 or 1.9; Battle-tested in the former.
64
+
65
+ For Rails 2 see the 0.3.x version of the gem which is maintained on the [rails2
66
+ branch](https://github.com/dasil003/validation_scopes/tree/rails2)
67
+
61
68
 
62
69
  ## Installation
63
70
 
@@ -69,7 +76,7 @@ In your Gemfile:
69
76
 
70
77
  gem 'validation_scopes'
71
78
 
72
- Or old-school Rails-style, in your environment.rb:
79
+ Or old-school-Rails-style, in your environment.rb:
73
80
 
74
81
  config.gem 'validation_scopes'
75
82
 
@@ -99,8 +106,8 @@ about the design process](http://www.darwinweb.net/articles/80) is on my blog.
99
106
 
100
107
  ## TODO
101
108
 
102
- * In Rails 3 validations are no longer coupled to ActiveRecord. As part of of ActiveModel, validations can be included
103
- in any object. It shouldn't be too much work to make validation_scopes work with arbitrary models as well.
109
+ * In Rails 3 validations are no longer coupled to ActiveRecord. Although the current version of the gem uses
110
+ ActiveModel, it hasn't been tested against arbitrary objects.
104
111
 
105
112
 
106
113
  ## Copyright
data/Rakefile CHANGED
@@ -1,6 +1,3 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
1
  begin
5
2
  require 'jeweler'
6
3
  Jeweler::Tasks.new do |gem|
@@ -11,7 +8,6 @@ begin
11
8
  gem.homepage = "http://github.com/dasil003/validation_scopes"
12
9
  gem.authors = ["Gabe da Silveira"]
13
10
  gem.add_development_dependency "shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
11
  end
16
12
  Jeweler::GemcutterTasks.new
17
13
  rescue LoadError
@@ -20,34 +16,11 @@ end
20
16
 
21
17
  require 'rake/testtask'
22
18
  Rake::TestTask.new(:test) do |test|
23
- test.libs << 'lib' << 'test'
19
+ test.libs << %w(lib test)
24
20
  test.pattern = 'test/**/test_*.rb'
25
21
  test.verbose = true
26
22
  end
27
23
 
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
24
  task :test => :check_dependencies
42
25
 
43
26
  task :default => :test
44
-
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "validation_scopes #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -9,6 +9,17 @@ module ValidationScopes
9
9
  module ClassMethods
10
10
  def validation_scope(scope)
11
11
  base_class = self
12
+ @all_scopes ||= []
13
+ class << self
14
+ def all_scopes=(scope)
15
+ @all_scopes << scope
16
+ end
17
+
18
+ def all_scopes
19
+ @all_scopes
20
+ end
21
+ end
22
+ self.all_scopes = scope
12
23
  deferred_proxy_class_declaration = Proc.new do
13
24
  proxy_class = Class.new(DelegateClass(base_class)) do
14
25
  include ActiveModel::Validations
data/test/db/schema.rb CHANGED
@@ -6,4 +6,11 @@ ActiveRecord::Schema.define do
6
6
  t.column "bio", :text
7
7
  t.column "sponsor_id", :integer
8
8
  end
9
- end
9
+
10
+ create_table "books" do |t|
11
+ t.column "title", :string
12
+ t.column "author", :string
13
+ t.column "isbn", :integer
14
+ t.column "user_id", :integer
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ one:
2
+ id: 1
3
+ title: Feature Selection for Knowledge Discovery and Data Mining
4
+ author: Huan Liu
5
+ isbn: 9780792381983
6
+ user_id: 1
7
+ two:
8
+ id: 2
9
+ title: SSL and TLS - theory and practice
10
+ author: Rolf Oppliger
11
+ isbn: 9781596934474
12
+ user_id: 1
data/test/helper.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'test/unit'
3
2
  require 'shoulda'
4
3
 
@@ -13,7 +12,10 @@ ActiveRecord::Base.establish_connection(
13
12
 
14
13
  require 'db/schema.rb'
15
14
 
16
- Dir['test/models/*.rb'].each { |f| require f }
15
+ Dir['./test/models/*.rb'].each { |f| require f }
17
16
 
18
17
  require 'active_record/fixtures'
19
- Fixtures.create_fixtures('test/fixtures/', ActiveRecord::Base.connection.tables)
18
+
19
+ fixtures_constant = defined?(ActiveRecord::Fixtures) ? ActiveRecord::Fixtures : Fixtures
20
+
21
+ fixtures_constant.create_fixtures('test/fixtures/', ActiveRecord::Base.connection.tables)
@@ -0,0 +1,13 @@
1
+ class Book < ActiveRecord::Base
2
+ belongs_to :user
3
+
4
+ validates_presence_of :title
5
+
6
+ validation_scope :warnings_book do |s|
7
+ s.validates_presence_of :author
8
+ end
9
+
10
+ validation_scope :alerts_book do |s|
11
+ s.validates_presence_of :isbn
12
+ end
13
+ end
data/test/models/user.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
2
  belongs_to :sponsor, :class_name => 'User'
3
+ has_many :books
3
4
 
4
5
  validates_presence_of :name
5
6
 
@@ -73,4 +73,21 @@ class TestValidationScopes < Test::Unit::TestCase
73
73
  @user.validation_scope_proxy_for_warnings.class.model_name
74
74
  end
75
75
  end
76
+
77
+ context "scopes per model" do
78
+ setup do
79
+ @user = User.find(1)
80
+ @book = Book.find(1)
81
+ @book2 = Book.find(2)
82
+ end
83
+
84
+ should "return all the scopes declared in User model" do
85
+ assert_equal [:warnings, :alerts], @user.class.all_scopes
86
+ end
87
+
88
+ should "return all the scopes declared in Book model" do
89
+ assert_equal [:warnings_book, :alerts_book], @book.class.all_scopes
90
+ assert_equal [:warnings_book, :alerts_book], @book2.class.all_scopes
91
+ end
92
+ end
76
93
  end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{validation_scopes}
8
- s.version = "0.4.0"
7
+ s.name = "validation_scopes"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Gabe da Silveira"]
12
- s.date = %q{2011-05-23}
13
- s.description = %q{Define additional sets of validations beyond the standard "errors" that is tied to the ActiveRecord life-cycle. These additional sets can be defined with all the standard ActiveRecord::Validation macros, and the resulting collection is a standard ActiveRecord::Errors object.}
14
- s.email = %q{gabe@websaviour.com}
12
+ s.date = "2012-04-15"
13
+ s.description = "Define additional sets of validations beyond the standard \"errors\" that is tied to the ActiveRecord life-cycle. These additional sets can be defined with all the standard ActiveRecord::Validation macros, and the resulting collection is a standard ActiveRecord::Errors object."
14
+ s.email = "gabe@websaviour.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.md"
@@ -25,22 +25,18 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/validation_scopes.rb",
27
27
  "test/db/schema.rb",
28
+ "test/fixtures/books.yml",
28
29
  "test/fixtures/users.yml",
29
30
  "test/helper.rb",
31
+ "test/models/book.rb",
30
32
  "test/models/user.rb",
31
33
  "test/test_validation_scopes.rb",
32
34
  "validation_scopes.gemspec"
33
35
  ]
34
- s.homepage = %q{http://github.com/dasil003/validation_scopes}
36
+ s.homepage = "http://github.com/dasil003/validation_scopes"
35
37
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.5.2}
37
- s.summary = %q{Create sets of validations independent of the life-cycle of an ActiveRecord object}
38
- s.test_files = [
39
- "test/db/schema.rb",
40
- "test/helper.rb",
41
- "test/models/user.rb",
42
- "test/test_validation_scopes.rb"
43
- ]
38
+ s.rubygems_version = "1.8.22"
39
+ s.summary = "Create sets of validations independent of the life-cycle of an ActiveRecord object"
44
40
 
45
41
  if s.respond_to? :specification_version then
46
42
  s.specification_version = 3
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_scopes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabe da Silveira
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-23 00:00:00 -05:00
19
- default_executable:
18
+ date: 2012-04-15 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: shoulda
@@ -50,12 +49,13 @@ files:
50
49
  - VERSION
51
50
  - lib/validation_scopes.rb
52
51
  - test/db/schema.rb
52
+ - test/fixtures/books.yml
53
53
  - test/fixtures/users.yml
54
54
  - test/helper.rb
55
+ - test/models/book.rb
55
56
  - test/models/user.rb
56
57
  - test/test_validation_scopes.rb
57
58
  - validation_scopes.gemspec
58
- has_rdoc: true
59
59
  homepage: http://github.com/dasil003/validation_scopes
60
60
  licenses: []
61
61
 
@@ -85,12 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  requirements: []
86
86
 
87
87
  rubyforge_project:
88
- rubygems_version: 1.5.2
88
+ rubygems_version: 1.8.22
89
89
  signing_key:
90
90
  specification_version: 3
91
91
  summary: Create sets of validations independent of the life-cycle of an ActiveRecord object
92
- test_files:
93
- - test/db/schema.rb
94
- - test/helper.rb
95
- - test/models/user.rb
96
- - test/test_validation_scopes.rb
92
+ test_files: []
93
+