rspec-active_record_mocks 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40ce063801a62757af06919137b882176628056a
4
- data.tar.gz: d66cf0572dd6518ccaf446ad7d728fb94e4258d5
3
+ metadata.gz: 38cfb7112f6a0144dceef2c1e3a7a576c59b64b8
4
+ data.tar.gz: 0daa8f5fd13d6897791ebd7fb81b740e03590685
5
5
  SHA512:
6
- metadata.gz: 275f739bf8909978777bf7b697a2f820ccecf260d12740405bfb7fda19208a5da41e9e0c875993b719470de56903b7f196a79d7916763f9397cef929606d4c1f
7
- data.tar.gz: 32a532e5c40d30410a53759d8ee588c92a7f739e6c6e345657de5455955ae420d84c085cd3f57a1e0b64ac5b36a71cebcd2d54d752e30385d6549ce5d9fa1ca3
6
+ metadata.gz: 3292bc48339616f24ff3a607b6d854a95e0675e27ecde84d6aee56473eba896ca8ebede5b2e9fc61f3fd834dd0fa5385c8bd078a0f1badc4525b3ac4d83592c2
7
+ data.tar.gz: 2de7c3d41efb70b2324c699c4a7b3ec84a474e428483cba1845996e0d34a6db46fb6e1c592867ad6e0ada77b80478b6ce4820dabb51da280925cc4f7e6c85d76
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
- gemspec :name => "Gem1"
2
+ gemspec :name => "active_record_mocks"
3
3
 
4
4
  group :development do
5
5
  unless ENV["CI"]
data/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Active Record Mocks.
2
2
 
3
- [![Build Status](https://travis-ci.org/envygeeks/active_record_mocks.png?branch=master)](https://travis-ci.org/envygeeks/active_record_mocks) [![Coverage Status](https://coveralls.io/repos/envygeeks/active_record_mocks/badge.png?branch=master)](https://coveralls.io/r/envygeeks/active_record_mocks) [![Code Climate](https://codeclimate.com/github/envygeeks/active_record_mocks.png)](https://codeclimate.com/github/envygeeks/active_record_mocks) [![Dependency Status](https://gemnasium.com/envygeeks/active_record_mocks.png)](https://gemnasium.com/envygeeks/active_record_mocks)
3
+ [![Build Status](https://travis-ci.org/envygeeks/ruby-active_record_mocks.png?branch=master)](https://travis-ci.org/envygeeks/ruby-active_record_mocks) [![Coverage Status](https://coveralls.io/repos/envygeeks/ruby-active_record_mocks/badge.png?branch=master)](https://coveralls.io/r/envygeeks/ruby-active_record_mocks) [![Code Climate](https://codeclimate.com/github/envygeeks/ruby-active_record_mocks.png)](https://codeclimate.com/github/envygeeks/ruby-active_record_mocks) [![Dependency Status](https://gemnasium.com/envygeeks/ruby-active_record_mocks.png)](https://gemnasium.com/envygeeks/ruby-active_record_mocks)
4
4
 
5
5
  ActiveRecord Mocks is designed to aide you in testing your ActiveRecord
6
6
  concerns by creating random models (or even named models) that are
@@ -147,3 +147,37 @@ with_mocked_tables do |m|
147
147
  end
148
148
  end
149
149
  ```
150
+
151
+ #### Using a custom parent class
152
+
153
+ If you need to test a base class that is not ActiveRecord::Base,
154
+ you can do so by specifying the `parent_class` method.
155
+
156
+ This is useful if your code base uses a custom base class that
157
+ derives from ActiveRecord::Base, like so:
158
+
159
+ ```ruby
160
+
161
+ class MyBase < ActiveRecord::Base
162
+ self.abstract_class = true
163
+ def a_custom_method
164
+ 42
165
+ end
166
+ end
167
+
168
+ with_mocked_tables do |m|
169
+ m.create_table migration_arguments do |t|
170
+ t.parent_class :MyBase
171
+ t.model_name :Foo
172
+ t.layout do |l|
173
+ l.text :foo_text
174
+ end
175
+ end
176
+
177
+ f = Foo.new
178
+ f.is_a?(MyBase) # <= true
179
+ f.a_custom_method # <= 42
180
+ end
181
+
182
+
183
+ ```
@@ -13,20 +13,21 @@ module ActiveRecordMocks
13
13
  @args = args
14
14
  @layout = nil
15
15
  @model_name = nil
16
+ @parent_class = nil
16
17
  end
17
18
 
18
- # ---------------------------------------------------------------
19
- # Tells us if we have already setup this model and object so
20
- # that we don't keep setting stuff up.
21
- # ---------------------------------------------------------------
19
+ # -----------------------------------------------------------------------
20
+ # Tells us if we have already setup this model and object so that we
21
+ # don't keep setting stuff up.
22
+ # -----------------------------------------------------------------------
22
23
 
23
24
  def setup?
24
25
  @already_setup ? true : false
25
26
  end
26
27
 
27
- # ---------------------------------------------------------------
28
+ # -----------------------------------------------------------------------
28
29
  # Gives the proper object of the model for you.
29
- # ---------------------------------------------------------------
30
+ # -----------------------------------------------------------------------
30
31
 
31
32
  def model
32
33
  if setup?
@@ -34,11 +35,11 @@ module ActiveRecordMocks
34
35
  end
35
36
  end
36
37
 
37
- # ---------------------------------------------------------------
38
- # Allows you to set the files that should be included into the
39
- # model, you must use t.includes because t.include is already
40
- # a method on the object you are in.
41
- # ---------------------------------------------------------------
38
+ # -----------------------------------------------------------------------
39
+ # Allows you to set the files that should be included into the model,
40
+ # you must use t.includes because t.include is already a method on the
41
+ # object you are in.
42
+ # -----------------------------------------------------------------------
42
43
 
43
44
  def includes(*incs)
44
45
  if setup? || incs.size == 0
@@ -52,20 +53,20 @@ module ActiveRecordMocks
52
53
  end
53
54
  end
54
55
 
55
- # ---------------------------------------------------------------
56
+ # -----------------------------------------------------------------------
56
57
  # Allows you to set the layout for the table you are building.
57
- # ---------------------------------------------------------------
58
+ # -----------------------------------------------------------------------
58
59
 
59
60
  def layout(&block)
60
61
  setup? || ! block_given? ? @layout ||= nil : @layout = block
61
62
  end
62
63
 
63
- # ---------------------------------------------------------------
64
- # Allows the setting of or setuping up of and returning of the
65
- # name of the table that is being used for the model. If
66
- # you do not customize this then it will be a tabelized name
67
- # of the model, the same way that normal active_record would do.
68
- # ---------------------------------------------------------------
64
+ # -----------------------------------------------------------------------
65
+ # Allows the setting of or setuping up of and returning of the name of
66
+ # the table that is being used for the model. If you do not customize
67
+ # this then it will be a tabelized name of the model, the same way that
68
+ # normal active_record would do.
69
+ # -----------------------------------------------------------------------
69
70
 
70
71
  def table_name(tname = nil)
71
72
  if setup? || (! tname && @table_name)
@@ -76,12 +77,12 @@ module ActiveRecordMocks
76
77
  end
77
78
  end
78
79
 
79
- # ---------------------------------------------------------------
80
- # Allows for the setting of or setup of and returning of the name
81
- # of the model being used, this should not be confused with model
82
- # which returns the actual object. The model need not match the
83
- # table and sometimes it won't if you chose to be that way.
84
- # ---------------------------------------------------------------
80
+ # -----------------------------------------------------------------------
81
+ # Allows for the setting of or setup of and returning of the name of the
82
+ # model being used, this should not be confused with model which returns
83
+ # the actual object. The model need not match the table and sometimes it
84
+ # won't if you chose to be that way.
85
+ # -----------------------------------------------------------------------
85
86
 
86
87
  def model_name(mname = nil)
87
88
  if setup? || (! mname && @model_name)
@@ -92,6 +93,21 @@ module ActiveRecordMocks
92
93
  end
93
94
  end
94
95
 
96
+ # -----------------------------------------------------------------------
97
+ # Allows the setting of or setup of and returning of the name of the
98
+ # parent class. If this is not customized it will default to
99
+ # ActiveRecord::Base
100
+ # -----------------------------------------------------------------------
101
+
102
+ def parent_class(cname=nil)
103
+ if setup? || (! cname && @parent_class)
104
+ @parent_class
105
+ else
106
+ @parent_class = cname ? cname.to_s.constantize : \
107
+ ActiveRecord::Base
108
+ end
109
+ end
110
+
95
111
  def setup_mocking!
96
112
  if ! setup?
97
113
  setup_table!
@@ -113,12 +129,16 @@ module ActiveRecordMocks
113
129
 
114
130
  private
115
131
  def setup_model!
116
- Object.const_set(model_name,
117
- Class.new(ActiveRecord::Base)).tap do |o|
118
- o.table_name = table_name
119
- setup_includes(o)
120
- run_model_methods(o)
132
+ definition = if Object.const_defined?(model_name)
133
+ then Object.const_get(model_name)
134
+ else Object.const_set(
135
+ model_name, Class.new(parent_class)
136
+ )
121
137
  end
138
+
139
+ definition.table_name = table_name
140
+ setup_includes(definition)
141
+ run_model_methods(definition)
122
142
  end
123
143
 
124
144
  private
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordMocks
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,115 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-active_record_mocks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordon Bedwell
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-20 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.2'
20
- - - <=
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4.1'
23
- requirement: !ruby/object:Gem::Requirement
22
+ version: '4.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - '>='
27
+ - - ">="
26
28
  - !ruby/object:Gem::Version
27
29
  version: '3.2'
28
- - - <=
30
+ - - "<"
29
31
  - !ruby/object:Gem::Version
30
- version: '4.1'
31
- prerelease: false
32
- type: :runtime
32
+ version: '4.3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: envygeeks-coveralls
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- version: '0.2'
40
35
  requirement: !ruby/object:Gem::Requirement
41
36
  requirements:
42
- - - ~>
37
+ - - "~>"
43
38
  - !ruby/object:Gem::Version
44
- version: '0.2'
45
- prerelease: false
39
+ version: '1.0'
46
40
  type: :development
47
- - !ruby/object:Gem::Dependency
48
- name: luna-rspec-formatters
41
+ prerelease: false
49
42
  version_requirements: !ruby/object:Gem::Requirement
50
43
  requirements:
51
- - - ~>
44
+ - - "~>"
52
45
  - !ruby/object:Gem::Version
53
- version: '1.2'
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: luna-rspec-formatters
54
49
  requirement: !ruby/object:Gem::Requirement
55
50
  requirements:
56
- - - ~>
51
+ - - "~>"
57
52
  - !ruby/object:Gem::Version
58
- version: '1.2'
59
- prerelease: false
53
+ version: '3.3'
60
54
  type: :development
61
- - !ruby/object:Gem::Dependency
62
- name: rspec
55
+ prerelease: false
63
56
  version_requirements: !ruby/object:Gem::Requirement
64
57
  requirements:
65
- - - ~>
58
+ - - "~>"
66
59
  - !ruby/object:Gem::Version
67
- version: '3.0'
60
+ version: '3.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
68
63
  requirement: !ruby/object:Gem::Requirement
69
64
  requirements:
70
- - - ~>
65
+ - - "~>"
71
66
  - !ruby/object:Gem::Version
72
- version: '3.0'
73
- prerelease: false
67
+ version: '3.3'
74
68
  type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.3'
75
75
  description: Mock ActiveRecord tables to test concerns and other code.
76
- email: envygeeks@gmail.com
76
+ email: jordon@envygeeks.io
77
77
  executables: []
78
78
  extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
- - Readme.md
81
+ - Gemfile
82
82
  - License
83
83
  - Rakefile
84
- - Gemfile
84
+ - Readme.md
85
85
  - lib/active_record_mocks.rb
86
86
  - lib/active_record_mocks/mock.rb
87
- - lib/active_record_mocks/version.rb
87
+ - lib/active_record_mocks/mock/table.rb
88
88
  - lib/active_record_mocks/rails.rb
89
89
  - lib/active_record_mocks/rspec.rb
90
- - lib/active_record_mocks/mock/table.rb
90
+ - lib/active_record_mocks/version.rb
91
91
  homepage: https://github.com/envygeeks/active_record_mocks
92
92
  licenses:
93
93
  - Apache 2.0
94
94
  metadata: {}
95
- post_install_message:
95
+ post_install_message:
96
96
  rdoc_options: []
97
97
  require_paths:
98
98
  - lib
99
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.1.9
112
- signing_key:
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.8
112
+ signing_key:
113
113
  specification_version: 4
114
114
  summary: Mock ActiveRecord tables to test.
115
115
  test_files: []