rails_agnostic_models 0.0.4 → 0.0.5
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 +1 -0
- data/acts_as_taggable_on.sqlite3 +0 -0
- data/lib/rails_agnostic_models/active_record_extensions.rb +6 -0
- data/lib/rails_agnostic_models/version.rb +1 -1
- data/rails_agnostic_models.gemspec +4 -0
- data/spec/rails_agnostic_models/version_agnostic_inheritance_column_spec.rb +23 -0
- data/spec/rails_agnostic_models/version_agnostic_scope_spec.rb +27 -0
- data/spec/spec_helper.rb +29 -0
- metadata +76 -6
- data/lib/rails_agnostic_models/rails_version_helpers.rb +0 -36
data/.gitignore
CHANGED
File without changes
|
@@ -46,6 +46,12 @@ module RailsAgnosticModels
|
|
46
46
|
yield
|
47
47
|
end
|
48
48
|
|
49
|
+
# safely refer to constants that may not be defined. Useful in a gem that might get included in places that might not define EVERY active record model, such as
|
50
|
+
# a satelite administration application. Note that you will still need to handle nil cases
|
51
|
+
def safe_constant(constant_sym)
|
52
|
+
return Object.const_get(constant_sym) if Object.const_defined? constant_sym
|
53
|
+
end
|
54
|
+
|
49
55
|
# Defines the appropraite scope based on the version of Rails
|
50
56
|
def version_agnostic_scope(*args)
|
51
57
|
if rails_2?
|
@@ -21,4 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "activerecord"
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
23
|
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "database_cleaner"
|
27
|
+
spec.add_development_dependency "debugger"
|
24
28
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
class Rails2Class < ActiveRecord::Base
|
3
|
+
end
|
4
|
+
class Rails3Class < ActiveRecord::Base
|
5
|
+
end
|
6
|
+
describe "#version_agnostic_inheritance_column" do
|
7
|
+
context "Rails 2" do
|
8
|
+
before { stub_const("Rails::VERSION::MAJOR", 2) }
|
9
|
+
it "set_inheritance_column for rails 2" do
|
10
|
+
Rails2Class.should_receive(:set_inheritance_column).with("type_inheritance")
|
11
|
+
Rails2Class.should_not_receive(:inheritance_column=).with("type_inheritance")
|
12
|
+
Rails2Class.send(:version_agnostic_inheritance_column, "type_inheritance")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "Rails 3" do
|
16
|
+
before { stub_const("Rails::VERSION::MAJOR", 3) }
|
17
|
+
it "inheritance_column= for rails 3" do
|
18
|
+
Rails2Class.should_not_receive(:set_inheritance_column).with("type_inheritance")
|
19
|
+
Rails2Class.should_receive(:inheritance_column=).with("type_inheritance")
|
20
|
+
Rails2Class.send(:version_agnostic_inheritance_column, "type_inheritance")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#version_agnostic_scope" do
|
4
|
+
context "Rails 2" do
|
5
|
+
class Rails2Class < ActiveRecord::Base
|
6
|
+
end
|
7
|
+
before { stub_const("Rails::VERSION::MAJOR", 2) }
|
8
|
+
let(:where) { Proc.new {where(active: true)} }
|
9
|
+
it "proxies to named scope for Rails 2" do
|
10
|
+
Rails2Class.should_receive(:named_scope).with(:active, where)
|
11
|
+
Rails2Class.should_not_receive(:scope).with(:active, where)
|
12
|
+
Rails2Class.send(:version_agnostic_scope, :active, where)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context "Rails 3" do
|
16
|
+
class Rails3Class < ActiveRecord::Base
|
17
|
+
end
|
18
|
+
|
19
|
+
before { stub_const("Rails::VERSION::MAJOR", 3) }
|
20
|
+
let(:where) { Proc.new {where(active: true)} }
|
21
|
+
it "proxies to scope for Rails 3" do
|
22
|
+
Rails3Class.should_not_receive(:named_scope).with(:active, where)
|
23
|
+
Rails3Class.should_receive(:scope).with(:active, where)
|
24
|
+
Rails3Class.send(:version_agnostic_scope, :active, where)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'yaml'
|
3
|
+
require 'database_cleaner'
|
4
|
+
require 'debugger'
|
5
|
+
|
6
|
+
database_yml = File.expand_path('../../spec/database.yml', __FILE__)
|
7
|
+
|
8
|
+
if File.exists?(database_yml)
|
9
|
+
active_record_configuration = YAML.load_file(database_yml)
|
10
|
+
|
11
|
+
ActiveRecord::Base.configurations = active_record_configuration
|
12
|
+
config = ActiveRecord::Base.configurations['sqlite3']
|
13
|
+
ActiveRecord::Base.establish_connection(config)
|
14
|
+
else
|
15
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'rails_agnostic_models'
|
19
|
+
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.before(:each) do
|
23
|
+
DatabaseCleaner.strategy = :transaction
|
24
|
+
DatabaseCleaner.start
|
25
|
+
end
|
26
|
+
config.after :each do
|
27
|
+
DatabaseCleaner.clean
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_agnostic_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -59,6 +59,70 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sqlite3
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
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: database_cleaner
|
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: debugger
|
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'
|
62
126
|
description: The purpose of this project is to ease the pain of upgrading Rails versions
|
63
127
|
by abstracting away differences between the Rails 2.3 and 3.2 API.
|
64
128
|
email:
|
@@ -72,11 +136,14 @@ files:
|
|
72
136
|
- LICENSE.txt
|
73
137
|
- README.md
|
74
138
|
- Rakefile
|
139
|
+
- acts_as_taggable_on.sqlite3
|
75
140
|
- lib/rails_agnostic_models.rb
|
76
141
|
- lib/rails_agnostic_models/active_record_extensions.rb
|
77
|
-
- lib/rails_agnostic_models/rails_version_helpers.rb
|
78
142
|
- lib/rails_agnostic_models/version.rb
|
79
143
|
- rails_agnostic_models.gemspec
|
144
|
+
- spec/rails_agnostic_models/version_agnostic_inheritance_column_spec.rb
|
145
|
+
- spec/rails_agnostic_models/version_agnostic_scope_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
80
147
|
homepage: ''
|
81
148
|
licenses:
|
82
149
|
- MIT
|
@@ -92,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
159
|
version: '0'
|
93
160
|
segments:
|
94
161
|
- 0
|
95
|
-
hash:
|
162
|
+
hash: -2644159498259307497
|
96
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
164
|
none: false
|
98
165
|
requirements:
|
@@ -101,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
168
|
version: '0'
|
102
169
|
segments:
|
103
170
|
- 0
|
104
|
-
hash:
|
171
|
+
hash: -2644159498259307497
|
105
172
|
requirements: []
|
106
173
|
rubyforge_project:
|
107
174
|
rubygems_version: 1.8.24
|
@@ -109,4 +176,7 @@ signing_key:
|
|
109
176
|
specification_version: 3
|
110
177
|
summary: Extends activerecord to provide rails-agnostic versions of common model code
|
111
178
|
to east the pain of upgrading
|
112
|
-
test_files:
|
179
|
+
test_files:
|
180
|
+
- spec/rails_agnostic_models/version_agnostic_inheritance_column_spec.rb
|
181
|
+
- spec/rails_agnostic_models/version_agnostic_scope_spec.rb
|
182
|
+
- spec/spec_helper.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module RailsAgnosticModels
|
2
|
-
module RailsVersionHelpers
|
3
|
-
module ClassMethods
|
4
|
-
def rails_2?
|
5
|
-
(defined? Rails) && (Rails::VERSION::MAJOR == 2)
|
6
|
-
end
|
7
|
-
|
8
|
-
def rails_3?
|
9
|
-
(defined? Rails) && (Rails::VERSION::MAJOR == 3)
|
10
|
-
end
|
11
|
-
|
12
|
-
def rails_4?
|
13
|
-
(defined? Rails) && (Rails::VERSION::MAJOR == 4)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Takes a block that will only be executed in a Rails 2 Project
|
17
|
-
def rails_2(&block)
|
18
|
-
return nil unless rails_2?
|
19
|
-
yield
|
20
|
-
end
|
21
|
-
|
22
|
-
def rails_3(&block)
|
23
|
-
return nil unless rails_3?
|
24
|
-
yield
|
25
|
-
end
|
26
|
-
|
27
|
-
def rails_4(&block)
|
28
|
-
return nil unless rails_4?
|
29
|
-
yield
|
30
|
-
end
|
31
|
-
end
|
32
|
-
sdef self.included(klass)
|
33
|
-
klass.extend(ClassMethods)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|