merged_default_scopes 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
22
  .bundle
23
+ debug.log
data/Gemfile CHANGED
@@ -1,5 +1,8 @@
1
+ source :gemcutter
2
+
1
3
  gem "activerecord", "~> 2.3.5"
2
4
 
3
5
  group :test do
4
6
  gem "rspec", ">= 2.0.0.beta.8"
7
+ gem "jeweler"
5
8
  end
data/History.markdown CHANGED
@@ -1,8 +1,12 @@
1
- # Version 0.0.2 / 2010-05-11
1
+ # Version 0.0.3 / 2010-05-16
2
+
3
+ * add clear_default_scope
4
+
5
+ # Version 0.0.2 / 2010-05-12
2
6
 
3
7
  * Now it actually works!
4
8
 
5
- # Version 0.0.1 / 2010-05-10
9
+ # Version 0.0.1 / 2010-05-11
6
10
 
7
11
  * Initial cut
8
12
  * Supports active_record-2.3.5 only
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 David Chelimsky
1
+ Copyright (c) 2010 David Chelimsky and Brian Tatnall
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,30 +1,68 @@
1
1
  # merged\_default\_scopes
2
2
 
3
- module SomeSoftDeletablePlugin
3
+ require 'merged_default_scopes'
4
+
5
+ module SomePlugin
4
6
  def self.included(mod)
5
7
  mod.default_scope :conditions => {:deleted_at => nil}
6
8
  end
7
9
  end
8
10
 
9
11
  class SomeModel < ActiveRecord::Base
10
- include SomeSoftDeletablePlugin # that may or may not be setting a default_scope
12
+ include SomePlugin
11
13
 
12
14
  default_scope :order => :name
13
15
  end
14
-
15
- # default_scope => {:find => {:order => :name, :conditions => {:deleted_at => nil}}}
16
+
17
+ SomeModel.__send__(:scope, :find)
18
+ # => {:order => :name, :conditions => {:deleted_at => nil}}
16
19
  #
17
20
  # ... and all is right with the world
18
21
 
19
- ## Note on Patches/Pull Requests
22
+ # clear\_default\_scope
23
+
24
+ require 'merged_default_scopes'
25
+
26
+ class SomeModel < ActiveRecord::Base
27
+ include SomePluginThatMightSetDefaultScope
28
+ include AnotherPluginThatMightSetDefaultScope
29
+
30
+ clear_default_scope
31
+ default_scope :order => :name
32
+ end
33
+
34
+ SomeModel.__send__(:scope, :find)
35
+ # => {:order => :name}
36
+ #
37
+ # ... and all is right with the world, assuming you want the old
38
+ # behaviour of default_scope, which is to overwrite previously set
39
+ # default scopes
40
+
41
+ ## Motivation
42
+
43
+ Sometimes plugins use `default_scope` to do what they do. We need a means of adding to
44
+ the default scope without blowing it away.
45
+
46
+ This is going to be the behaviour of default_scope and clear_default_scope in
47
+ rails-3 (as of http://github.com/rails/rails/commit/35a114a8941cb22d29a536f1215a23a8cf7c4756),
48
+ so this gem serves as a back-port to rails-2.
49
+
50
+ ## Install
51
+
52
+ $ gem install merged_default_scopes
53
+
54
+ ## Contribute
20
55
 
21
- * Fork the project.
22
- * Make your feature addition or bug fix.
23
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
24
- * Commit, do not mess with rakefile, version, or history.
25
- (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)
26
- * Send me a pull request. Bonus points for topic branches.
56
+ * [Fork the project](http://github.com/dchelimsky/merged_default_scopes)
57
+ * Make the code better with a new feature, bug fix, or refactoring.
58
+ * New features and bug fixes should have specs.
59
+ * Send us a pull request.
60
+
61
+ ## Learn more
62
+
63
+ * [code/docs](http://github.com/dchelimsky/merged_default_scopes)
64
+ * [issues](http://github.com/dchelimsky/merged_default_scopes/issues)
27
65
 
28
66
  ## Copyright
29
67
 
30
- Copyright (c) 2010 David Chelimsky and Brain Tatnall. See LICENSE for details.
68
+ Copyright (c) 2010 David Chelimsky and Brian Tatnall. See LICENSE for details.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "merged_default_scopes"
8
8
  gem.summary = %Q{the name says it all}
9
- gem.description = %Q{modify behavior of default_scope method to merge rather than override}
9
+ gem.description = %Q{modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite}
10
10
  gem.email = "dchelimsky@gmail.com,btatnall@gmail.com"
11
11
  gem.homepage = "http://github.com/dchelimsky/merged_default_scopes"
12
12
  gem.authors = ["David Chelimsky", "Brian Tatnall"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -12,6 +12,10 @@ module MergedDefaultScopes
12
12
  end
13
13
  end
14
14
  end
15
+
16
+ def clear_default_scope
17
+ scoped_methods.clear
18
+ end
15
19
  end
16
20
 
17
21
  def self.included(mod)
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{merged_default_scopes}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Brian Tatnall"]
12
- s.date = %q{2010-05-12}
13
- s.description = %q{modify behavior of default_scope method to merge rather than override}
12
+ s.date = %q{2010-05-16}
13
+ s.description = %q{modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite}
14
14
  s.email = %q{dchelimsky@gmail.com,btatnall@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "autotest/discover.rb",
31
31
  "lib/merged_default_scopes.rb",
32
32
  "merged_default_scopes.gemspec",
33
+ "spec/db/schema.rb",
33
34
  "spec/merged_default_scopes_spec.rb",
34
35
  "spec/spec_helper.rb"
35
36
  ]
@@ -39,7 +40,8 @@ Gem::Specification.new do |s|
39
40
  s.rubygems_version = %q{1.3.6}
40
41
  s.summary = %q{the name says it all}
41
42
  s.test_files = [
42
- "spec/merged_default_scopes_spec.rb",
43
+ "spec/db/schema.rb",
44
+ "spec/merged_default_scopes_spec.rb",
43
45
  "spec/spec_helper.rb"
44
46
  ]
45
47
 
data/spec/db/schema.rb ADDED
@@ -0,0 +1,7 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ create_table :some_models do |t|
3
+ t.column :deleted_at, :datetime
4
+ t.column :name, :string
5
+ end
6
+ end
7
+
@@ -1,33 +1,26 @@
1
1
  require "spec_helper"
2
2
 
3
- class SomeModel < ActiveRecord::Base
4
- def initialize
5
- @columns = []
6
- end
7
-
8
- def self.columns
9
- @columns ||= [];
10
- end
11
-
12
- def self.column(name, sql_type = nil, default = nil, null = true)
13
- columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
14
- end
15
-
16
- column :deleted_at, :datetime
17
- column :name, :string
18
- end
3
+ class SomeModel < ActiveRecord::Base; end
19
4
 
20
5
  describe MergedDefaultScopes do
6
+ after(:each) do
7
+ SomeModel.__send__ :clear_default_scope
8
+ end
21
9
  describe "#default_scope" do
22
- before(:each) do
10
+ it "merges multiple calls" do
23
11
  SomeModel.__send__ :default_scope, :order => :name
24
12
  SomeModel.__send__ :default_scope, :conditions => {:deleted_at => nil}
25
- end
26
-
27
- it "merges multiple calls" do
28
13
  SomeModel.__send__(:scope, :find).
29
14
  should == {:order => :name, :conditions => {:deleted_at => nil}}
30
15
  end
31
16
  end
32
- end
33
17
 
18
+ describe "#clear_default_scope" do
19
+ it "clears default scopes" do
20
+ SomeModel.__send__ :default_scope, :order => :name
21
+ SomeModel.__send__ :default_scope, :conditions => {:deleted_at => nil}
22
+ SomeModel.__send__ :clear_default_scope
23
+ SomeModel.__send__(:scope, :find).should be_nil
24
+ end
25
+ end
26
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,16 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  require 'merged_default_scopes'
3
3
  require 'rspec'
4
+ require "sqlite3"
5
+
6
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
7
+ ActiveRecord::Base.establish_connection(
8
+ :adapter => "sqlite3",
9
+ :database => ":memory:"
10
+ )
11
+ ActiveRecord::Migration.verbose = false
12
+ load(File.dirname(__FILE__) + "/db/schema.rb")
13
+
14
+ class AuditableModel < ActiveRecord::Base; end
15
+
4
16
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Chelimsky
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-12 00:00:00 -05:00
18
+ date: 2010-05-16 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 2.0.0.beta.8
35
35
  type: :development
36
36
  version_requirements: *id001
37
- description: modify behavior of default_scope method to merge rather than override
37
+ description: modify behavior of ActiveRecord::Base::default_scope to merge rather than overwrite
38
38
  email: dchelimsky@gmail.com,btatnall@gmail.com
39
39
  executables: []
40
40
 
@@ -57,6 +57,7 @@ files:
57
57
  - autotest/discover.rb
58
58
  - lib/merged_default_scopes.rb
59
59
  - merged_default_scopes.gemspec
60
+ - spec/db/schema.rb
60
61
  - spec/merged_default_scopes_spec.rb
61
62
  - spec/spec_helper.rb
62
63
  has_rdoc: true
@@ -90,5 +91,6 @@ signing_key:
90
91
  specification_version: 3
91
92
  summary: the name says it all
92
93
  test_files:
94
+ - spec/db/schema.rb
93
95
  - spec/merged_default_scopes_spec.rb
94
96
  - spec/spec_helper.rb