with_model 0.1 → 0.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.
- data/gemfiles/Gemfile.common +2 -0
- data/gemfiles/rspec1/Gemfile.lock +2 -0
- data/gemfiles/rspec2/Gemfile.lock +2 -0
- data/lib/with_model/base.rb +27 -0
- data/lib/with_model/dsl.rb +5 -6
- data/lib/with_model/version.rb +1 -1
- data/spec/with_model_spec.rb +29 -0
- data/with_model.gemspec +1 -0
- metadata +23 -2
data/gemfiles/Gemfile.common
CHANGED
@@ -5,6 +5,7 @@ GEM
|
|
5
5
|
activesupport (= 2.3.5)
|
6
6
|
activesupport (2.3.5)
|
7
7
|
autotest (4.4.2)
|
8
|
+
mixico (0.1.4)
|
8
9
|
rspec (1.3.1)
|
9
10
|
sqlite3-ruby (1.3.2)
|
10
11
|
|
@@ -14,5 +15,6 @@ PLATFORMS
|
|
14
15
|
DEPENDENCIES
|
15
16
|
activerecord (~> 2.3.5)
|
16
17
|
autotest
|
18
|
+
mixico
|
17
19
|
rspec (~> 1.0)
|
18
20
|
sqlite3-ruby
|
@@ -16,6 +16,7 @@ GEM
|
|
16
16
|
builder (2.1.2)
|
17
17
|
diff-lcs (1.1.2)
|
18
18
|
i18n (0.4.2)
|
19
|
+
mixico (0.1.4)
|
19
20
|
rspec (2.1.0)
|
20
21
|
rspec-core (~> 2.1.0)
|
21
22
|
rspec-expectations (~> 2.1.0)
|
@@ -33,5 +34,6 @@ PLATFORMS
|
|
33
34
|
DEPENDENCIES
|
34
35
|
activerecord (~> 3.0.0)
|
35
36
|
autotest
|
37
|
+
mixico
|
36
38
|
rspec (~> 2.0)
|
37
39
|
sqlite3-ruby
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mixico'
|
2
|
+
|
3
|
+
module WithModel
|
4
|
+
class Base < ActiveRecord::Base
|
5
|
+
class << self
|
6
|
+
def with_model?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def include(*args)
|
11
|
+
@modules_to_unmix ||= []
|
12
|
+
args.each do |mod|
|
13
|
+
unless @modules_to_unmix.include?(mod)
|
14
|
+
@modules_to_unmix << mod
|
15
|
+
end
|
16
|
+
end
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def _with_model_deconstructor
|
21
|
+
@modules_to_unmix.each do |mod|
|
22
|
+
disable_mixin mod
|
23
|
+
end if defined?(@modules_to_unmix)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/with_model/dsl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'with_model/base'
|
2
|
+
|
1
3
|
module WithModel
|
2
4
|
class Dsl
|
3
5
|
attr_reader :model_initialization
|
@@ -18,22 +20,19 @@ module WithModel
|
|
18
20
|
attr_accessor name
|
19
21
|
end
|
20
22
|
|
23
|
+
model = Class.new(WithModel::Base)
|
24
|
+
|
21
25
|
example_group.before do
|
22
|
-
model = Class.new(ActiveRecord::Base)
|
23
26
|
silence_warnings { Object.const_set(const_name, model) }
|
24
27
|
Object.const_get(const_name).class_eval do
|
25
28
|
set_table_name table_name
|
26
|
-
class << self
|
27
|
-
def with_model?
|
28
|
-
true
|
29
|
-
end
|
30
|
-
end
|
31
29
|
self.class_eval(&dsl.model_initialization)
|
32
30
|
end
|
33
31
|
send("#{name}=", model)
|
34
32
|
end
|
35
33
|
|
36
34
|
example_group.after do
|
35
|
+
model._with_model_deconstructor
|
37
36
|
Object.send(:remove_const, const_name)
|
38
37
|
Object.const_set(const_name, original_const_value) if original_const_defined
|
39
38
|
end
|
data/lib/with_model/version.rb
CHANGED
data/spec/with_model_spec.rb
CHANGED
@@ -95,4 +95,33 @@ describe "a temporary ActiveRecord model created with with_model" do
|
|
95
95
|
BlogPosts.should == blog_posts
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
module AMixin
|
100
|
+
def foo
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with a mixin" do
|
105
|
+
with_model :with_a_mixin do
|
106
|
+
table {}
|
107
|
+
model do
|
108
|
+
include AMixin
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
before { ::ModelWithMixin = WithAMixin }
|
113
|
+
|
114
|
+
it "should have the mixin" do
|
115
|
+
lambda { ::ModelWithMixin.new.foo }.should_not raise_error
|
116
|
+
::ModelWithMixin.include?(AMixin).should be_true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "after a context that uses a mixin" do
|
121
|
+
it "should not have the mixin" do
|
122
|
+
lambda { ::ModelWithMixin.new.foo }.should raise_error(NoMethodError)
|
123
|
+
::ModelWithMixin.include?(AMixin).should be_false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
98
127
|
end
|
data/with_model.gemspec
CHANGED
metadata
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: with_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
9
11
|
platform: ruby
|
10
12
|
authors:
|
11
13
|
- Case Commons, LLC
|
@@ -13,7 +15,7 @@ autorequire:
|
|
13
15
|
bindir: bin
|
14
16
|
cert_chain: []
|
15
17
|
|
16
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-22 00:00:00 -05:00
|
17
19
|
default_executable:
|
18
20
|
dependencies:
|
19
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,6 +26,7 @@ dependencies:
|
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
27
30
|
segments:
|
28
31
|
- 2
|
29
32
|
- 3
|
@@ -31,6 +34,7 @@ dependencies:
|
|
31
34
|
version: 2.3.5
|
32
35
|
- - <
|
33
36
|
- !ruby/object:Gem::Version
|
37
|
+
hash: 63
|
34
38
|
segments:
|
35
39
|
- 4
|
36
40
|
- 0
|
@@ -38,6 +42,20 @@ dependencies:
|
|
38
42
|
version: 4.0.0
|
39
43
|
type: :runtime
|
40
44
|
version_requirements: *id001
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: mixico
|
47
|
+
prerelease: false
|
48
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id002
|
41
59
|
description: Dynamically build a model within an Rspec context
|
42
60
|
email:
|
43
61
|
- casecommons-dev@googlegroups.com
|
@@ -60,6 +78,7 @@ files:
|
|
60
78
|
- gemfiles/rspec2/Gemfile
|
61
79
|
- gemfiles/rspec2/Gemfile.lock
|
62
80
|
- lib/with_model.rb
|
81
|
+
- lib/with_model/base.rb
|
63
82
|
- lib/with_model/dsl.rb
|
64
83
|
- lib/with_model/version.rb
|
65
84
|
- spec/active_record_behaviors_spec.rb
|
@@ -80,6 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
99
|
requirements:
|
81
100
|
- - ">="
|
82
101
|
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
83
103
|
segments:
|
84
104
|
- 0
|
85
105
|
version: "0"
|
@@ -88,6 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
108
|
requirements:
|
89
109
|
- - ">="
|
90
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
91
112
|
segments:
|
92
113
|
- 0
|
93
114
|
version: "0"
|