remarkable_activerecord 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,16 +8,16 @@ module Remarkable
8
8
  optionals :select, :conditions, :include, :group, :having, :order, :limit, :offset, :finder_sql, :counter_sql
9
9
  optionals :uniq, :readonly, :validate, :autosave, :polymorphic, :counter_cache, :default => true
10
10
 
11
- collection_assertions :association_exists?, :macro_matches?, :through_exists?, :source_exists?,
12
- :join_table_exists?, :foreign_key_exists?, :polymorphic_exists?,
11
+ collection_assertions :association_exists?, :macro_matches?, :through_exists?, :source_exists?,
12
+ :klass_exists?, :join_table_exists?, :foreign_key_exists?, :polymorphic_exists?,
13
13
  :counter_cache_exists?, :options_match?
14
14
 
15
15
  protected
16
16
 
17
17
  def association_exists?
18
18
  reflection
19
- end
20
-
19
+ end
20
+
21
21
  def macro_matches?
22
22
  reflection.macro == @macro
23
23
  end
@@ -30,6 +30,10 @@ module Remarkable
30
30
  def source_exists?
31
31
  return true unless @options.key?(:through)
32
32
  reflection.source_reflection rescue false
33
+ end
34
+
35
+ def klass_exists?
36
+ reflection.klass rescue nil
33
37
  end
34
38
 
35
39
  # has_and_belongs_to_many only works if the tables are in the same
@@ -73,10 +77,17 @@ module Remarkable
73
77
  def reflection
74
78
  @reflection ||= subject_class.reflect_on_association(@association.to_sym)
75
79
  end
80
+
81
+ def subject_table_name
82
+ subject_class.table_name.to_s
83
+ end
76
84
 
77
- # Rescue nil to avoid raising errors in invalid through associations
78
85
  def reflection_class_name
79
86
  reflection.class_name.to_s rescue nil
87
+ end
88
+
89
+ def reflection_table_name
90
+ reflection.klass.table_name.to_s rescue nil
80
91
  end
81
92
 
82
93
  def reflection_foreign_key
@@ -107,9 +118,9 @@ module Remarkable
107
118
  elsif reflection.macro == :has_and_belongs_to_many
108
119
  reflection.options[:join_table]
109
120
  elsif reflection.macro == :belongs_to
110
- subject_class.table_name
121
+ subject_table_name
111
122
  else
112
- reflection.klass.table_name
123
+ reflection_table_name
113
124
  end
114
125
  end
115
126
 
@@ -132,14 +143,14 @@ module Remarkable
132
143
  if @subject && reflection
133
144
  options.merge!(
134
145
  :actual_macro => Remarkable.t(reflection.macro, :scope => matcher_i18n_scope, :default => reflection.macro.to_s),
135
- :subject_table => subject_class.table_name.inspect,
136
- :reflection_table => reflection.klass.table_name.inspect,
146
+ :subject_table => subject_table_name.inspect,
147
+ :reflection_table => reflection_table_name.inspect,
137
148
  :foreign_key_table => foreign_key_table.inspect,
138
149
  :polymorphic_column => reflection_foreign_key.sub(/_id$/, '_type').inspect,
139
150
  :counter_cache_column => reflection.counter_cache_column.to_s.inspect,
140
151
  :join_table => reflection.options[:join_table].inspect,
141
152
  :foreign_key => reflection_foreign_key.inspect
142
- ) rescue nil # rescue to allow specs to run properly
153
+ )
143
154
  end
144
155
 
145
156
  options
data/locale/en.yml CHANGED
@@ -53,10 +53,11 @@ en:
53
53
  has_one: have one
54
54
  description: "{{macro}} {{associations}}"
55
55
  expectations:
56
- association_exists: "{{subject_name}} records {{macro}} {{association}}, got no association"
56
+ association_exists: "{{subject_name}} records {{macro}} {{association}}, but the association does not exist"
57
57
  macro_matches: "{{subject_name}} records {{macro}} {{association}}, got {{subject_name}} records {{actual_macro}} {{association}}"
58
58
  through_exists: "{{subject_name}} records {{macro}} {{association}} through {{through}}, through association does not exist"
59
- source_exists: "{{subject_name}} records {{macro}} {{association}} through {{through}}, source association does not exist"
59
+ source_exists: "{{subject_name}} records {{macro}} {{association}} through {{through}}, source association does not exist"
60
+ klass_exists: "{{subject_name}} records {{macro}} {{association}}, but the association class does not exist"
60
61
  join_table_exists: "join table {{join_table}} to exist, but does not"
61
62
  foreign_key_exists: "foreign key {{foreign_key}} to exist on {{foreign_key_table}}, but does not"
62
63
  polymorphic_exists: "{{subject_table}} to have {{polymorphic_column}} as column, but does not"
@@ -8,11 +8,13 @@ describe 'association_matcher' do
8
8
  # Defines a model, create a validation and returns a raw matcher
9
9
  def define_and_validate(options={})
10
10
  columns = options.delete(:association_columns) || { :projects_count => :integer }
11
- define_model :company, columns
11
+ define_model :company, columns
12
+ define_model :super_company, columns
12
13
 
13
14
  columns = options.delete(:model_columns) || { :company_id => :integer, :company_type => :string }
14
15
  @model = define_model :project, columns do
15
- belongs_to :company, options
16
+ belongs_to :company, options
17
+ belongs_to :unknown
16
18
  end
17
19
 
18
20
  belong_to :company
@@ -47,7 +49,7 @@ describe 'association_matcher' do
47
49
  define_and_validate
48
50
  matcher = belong_to('whatever')
49
51
  matcher.matches?(@model)
50
- matcher.failure_message.should == 'Expected Project records belong to whatever, got no association'
52
+ matcher.failure_message.should == 'Expected Project records belong to whatever, but the association does not exist'
51
53
  end
52
54
 
53
55
  it 'should set macro_matches? message' do
@@ -55,6 +57,13 @@ describe 'association_matcher' do
55
57
  matcher = have_one('company')
56
58
  matcher.matches?(@model)
57
59
  matcher.failure_message.should == 'Expected Project records have one company, got Project records belong to company'
60
+ end
61
+
62
+ it 'should set klass_exists? message' do
63
+ define_and_validate
64
+ matcher = belong_to('unknown')
65
+ matcher.matches?(@model)
66
+ matcher.failure_message.should == 'Expected Project records belong to unknown, but the association class does not exist'
58
67
  end
59
68
 
60
69
  it 'should set foreign_key_exists? message' do
@@ -92,7 +101,8 @@ describe 'association_matcher' do
92
101
  describe 'without options' do
93
102
  before(:each){ define_and_validate }
94
103
 
95
- it { should belong_to(:company) }
104
+ it { should belong_to(:company) }
105
+ it { should_not belong_to(:unknown) }
96
106
  it { should_not belong_to(:project) }
97
107
  it { should_not have_one(:company) }
98
108
  it { should_not have_many(:company) }
@@ -157,7 +167,8 @@ describe 'association_matcher' do
157
167
  m.class_name = "Company"
158
168
  m.foreign_key = :company_id
159
169
  end
160
-
170
+
171
+ should_not_belong_to :unknown
161
172
  should_not_belong_to :project
162
173
  should_not_have_one :company
163
174
  should_not_have_many :companies
@@ -173,7 +184,8 @@ describe 'association_matcher' do
173
184
 
174
185
  # Defines a model, create a validation and returns a raw matcher
175
186
  def define_and_validate(options={})
176
- define_model :label
187
+ define_model :label
188
+ define_model :super_label
177
189
 
178
190
  columns = options.delete(:association_columns) || [ :label_id, :project_id ]
179
191
  create_table(options.delete(:association_table) || :labels_projects) do |table|
@@ -209,7 +221,7 @@ describe 'association_matcher' do
209
221
  define_and_validate
210
222
  matcher = have_and_belong_to_many('whatever')
211
223
  matcher.matches?(@model)
212
- matcher.failure_message.should == 'Expected Project records have and belong to many whatever, got no association'
224
+ matcher.failure_message.should == 'Expected Project records have and belong to many whatever, but the association does not exist'
213
225
  end
214
226
 
215
227
  it 'should set macro_matches? message' do
@@ -365,7 +377,7 @@ describe 'association_matcher' do
365
377
  define_and_validate
366
378
  matcher = have_many('whatever')
367
379
  matcher.matches?(@model)
368
- matcher.failure_message.should == 'Expected Project records have many whatever, got no association'
380
+ matcher.failure_message.should == 'Expected Project records have many whatever, but the association does not exist'
369
381
  end
370
382
 
371
383
  it 'should set macro_matches? message' do
@@ -502,7 +514,8 @@ describe 'association_matcher' do
502
514
 
503
515
  @model = define_model :project, options.delete(:model_columns) || {} do
504
516
  has_many :project_managers unless options.delete(:skip_through)
505
- has_one :manager, options
517
+ has_one :manager, options
518
+ has_one :unknown
506
519
  end
507
520
 
508
521
  have_one :manager
@@ -524,8 +537,15 @@ describe 'association_matcher' do
524
537
  define_and_validate
525
538
  matcher = have_one('whatever')
526
539
  matcher.matches?(@model)
527
- matcher.failure_message.should == 'Expected Project records have one whatever, got no association'
540
+ matcher.failure_message.should == 'Expected Project records have one whatever, but the association does not exist'
528
541
  end
542
+
543
+ it 'should set klass_exists? message' do
544
+ define_and_validate
545
+ matcher = have_one('unknown')
546
+ matcher.matches?(@model)
547
+ matcher.failure_message.should == 'Expected Project records have one unknown, but the association class does not exist'
548
+ end
529
549
 
530
550
  it 'should set macro_matches? message' do
531
551
  define_and_validate
@@ -570,7 +590,8 @@ describe 'association_matcher' do
570
590
  describe 'without options' do
571
591
  before(:each){ define_and_validate }
572
592
 
573
- it { should have_one(:manager) }
593
+ it { should have_one(:manager) }
594
+ it { should_not have_one(:unknown) }
574
595
  it { should_not belong_to(:manager) }
575
596
  it { should_not have_many(:managers) }
576
597
  it { should_not have_and_belong_to_many(:managers) }
@@ -634,7 +655,8 @@ describe 'association_matcher' do
634
655
  m.validate
635
656
  m.through = :project_managers
636
657
  end
637
-
658
+
659
+ should_not_have_one :unknown
638
660
  should_not_have_one :manager, :validate => false
639
661
  should_not_have_one :manager, :through => :another_thing
640
662
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remarkable_activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Brando
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2009-05-29 00:00:00 +02:00
14
+ date: 2009-06-04 00:00:00 +02:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.1.4
35
+ version: 3.1.5
36
36
  version:
37
37
  description: "Remarkable ActiveRecord: collection of matchers and macros with I18n for ActiveRecord"
38
38
  email: