rich-acts_as_revisable 1.1.0 → 1.1.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.
@@ -1,5 +1,6 @@
1
1
  require 'acts_as_revisable/options'
2
2
  require 'acts_as_revisable/quoted_columns'
3
+ require 'acts_as_revisable/validations'
3
4
  require 'acts_as_revisable/acts/common'
4
5
  require 'acts_as_revisable/acts/revision'
5
6
  require 'acts_as_revisable/acts/revisable'
@@ -45,6 +46,7 @@ module WithoutScope
45
46
  self.revisable_options = Options.new(options, &block)
46
47
 
47
48
  self.send(:include, Common)
49
+ self.send(:extend, Validations) unless self.revisable_options.no_validation_scoping?
48
50
  self.send(:include, WithoutScope::QuotedColumnConditions)
49
51
  end
50
52
  end
@@ -0,0 +1,11 @@
1
+ module WithoutScope
2
+ module ActsAsRevisable
3
+ module Validations
4
+ def validates_uniqueness_of(*args)
5
+ options = args.extract_options!
6
+ (options[:scope] ||= []) << :revisable_is_current
7
+ super(*(args << options))
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,7 +3,7 @@ module WithoutScope #:nodoc:
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 1
5
5
  MINOR = 1
6
- TINY = 0
6
+ TINY = 1
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
9
9
  end
@@ -97,11 +97,15 @@ class Session < ActiveRecord::Base
97
97
  end
98
98
 
99
99
  class Foo < ActiveRecord::Base
100
- acts_as_revisable :generate_revision_class => true
100
+ acts_as_revisable :generate_revision_class => true, :no_validation_scoping => true
101
+
102
+ validates_uniqueness_of :name
101
103
  end
102
104
 
103
105
  class Post < ActiveRecord::Base
104
- acts_as_revisable
106
+ acts_as_revisable
107
+
108
+ validates_uniqueness_of :name
105
109
  end
106
110
 
107
111
  class PostRevision < ActiveRecord::Base
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe WithoutScope::ActsAsRevisable, "with validations" do
4
+ after(:each) do
5
+ cleanup_db
6
+ end
7
+
8
+ before(:each) do
9
+ @post = Post.create(:name => 'a post')
10
+ @foo = Foo.create(:name => 'a foo')
11
+
12
+ end
13
+
14
+ describe "unique fields" do
15
+ it "should allow revisions" do
16
+ lambda {@post.revise!; @post.revise!}.should_not raise_error
17
+ end
18
+ end
19
+
20
+ describe "unique fields with validation scoping off" do
21
+ it "should not allow revisions" do
22
+ lambda {@foo.revise!; @foo.revise!}.should raise_error
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rich-acts_as_revisable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Cavanaugh
@@ -38,6 +38,7 @@ files:
38
38
  - spec/spec.opts
39
39
  - spec/spec_helper.rb
40
40
  - spec/sti_spec.rb
41
+ - spec/validations_spec.rb
41
42
  - lib/acts_as_revisable
42
43
  - lib/acts_as_revisable/acts
43
44
  - lib/acts_as_revisable/acts/common.rb
@@ -48,6 +49,7 @@ files:
48
49
  - lib/acts_as_revisable/gem_spec_options.rb
49
50
  - lib/acts_as_revisable/options.rb
50
51
  - lib/acts_as_revisable/quoted_columns.rb
52
+ - lib/acts_as_revisable/validations.rb
51
53
  - lib/acts_as_revisable/version.rb
52
54
  - lib/acts_as_revisable.rb
53
55
  - generators/revisable_migration