weighted_average 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -30,7 +30,8 @@ module ActiveRecord
30
30
  # set up join ON
31
31
  join_on = if association_class
32
32
  raise ArgumentError, "#{association.primary_key_name} isn't a column in the #{association_class.table_name} table" unless association_class.column_names.include?(association.primary_key_name)
33
- foreign_arel_table[association.primary_key_name].eq arel_table[primary_key]
33
+ join_key = association.options[:primary_key].present? ? association.options[:primary_key] : primary_key
34
+ foreign_arel_table[association.primary_key_name].eq arel_table[join_key]
34
35
  end
35
36
 
36
37
  # 'weighting'
data/test/helper.rb CHANGED
@@ -23,11 +23,11 @@ ActiveRecord::Base.establish_connection(
23
23
  'adapter' => 'mysql',
24
24
  'database' => 'weighted_average_test',
25
25
  'username' => 'root',
26
- 'password' => ''
26
+ 'password' => 'password'
27
27
  )
28
28
 
29
29
  ActiveSupport::Inflector.inflections do |inflect|
30
- inflect.uncountable %w{aircraft airline_aircraft}
30
+ inflect.uncountable %w{aircraft airline_aircraft aircraft_deux AircraftDeux}
31
31
  inflect.uncountable 'commons'
32
32
  inflect.uncountable 'food'
33
33
  inflect.uncountable 'shelter'
@@ -126,6 +126,33 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
126
126
  t.integer "bts_aircraft_type"
127
127
  end
128
128
 
129
+ create_table "aircraft_deux", :id => false, :force => true do |t|
130
+ t.string 'icao_code'
131
+ t.string "name"
132
+ t.integer "seats"
133
+ t.integer "fuel_type_id"
134
+ t.float "endpoint_fuel"
135
+ t.integer "manufacturer_id"
136
+ t.datetime "updated_at"
137
+ t.datetime "created_at"
138
+ t.date "bts_begin_date"
139
+ t.date "bts_end_date"
140
+ t.float "load_factor"
141
+ t.float "freight_share"
142
+ t.float "m3"
143
+ t.float "m2"
144
+ t.float "m1"
145
+ t.float "distance"
146
+ t.float "payload"
147
+ t.integer "aircraft_class_id"
148
+ t.float "multiplier"
149
+ t.string "manufacturer_name"
150
+ t.string "brighter_planet_aircraft_class_code"
151
+ t.integer "weighting"
152
+ t.integer "my_bts_aircraft_type_code"
153
+ end
154
+ execute 'ALTER TABLE aircraft_deux ADD PRIMARY KEY (icao_code);'
155
+
129
156
  create_table "aircraft_classes", :force => true do |t|
130
157
  t.string "name"
131
158
  t.integer "seats"
@@ -218,3 +245,8 @@ class AircraftClass < ActiveRecord::Base
218
245
  has_many :aircraft, :class_name => 'Aircraft'
219
246
  has_many :airline_aircraft_seat_classes, :through => :aircraft
220
247
  end
248
+
249
+ class AircraftDeux < ActiveRecord::Base
250
+ set_primary_key 'icao_code'
251
+ has_many :segments, :class_name => "Segment", :primary_key => 'my_bts_aircraft_type_code', :foreign_key => 'bts_aircraft_type'
252
+ end
@@ -109,6 +109,13 @@ class TestWeightedAverage < Test::Unit::TestCase
109
109
  )
110
110
  end
111
111
 
112
+ should "do foreign custom weighting with custom join keys" do
113
+ should_have_same_sql(
114
+ "SELECT (SUM((`aircraft_deux`.`m3`) * `segments`.`passengers`) / SUM(`segments`.`passengers`)) AS weighted_average, 12345 FROM `aircraft_deux` LEFT OUTER JOIN `segments` ON `segments`.`bts_aircraft_type` = `aircraft_deux`.`my_bts_aircraft_type_code` WHERE (`aircraft_deux`.`m3` IS NOT NULL)",
115
+ AircraftDeux.weighted_average_relation(:m3, :weighted_by => [:segments, :passengers])
116
+ )
117
+ end
118
+
112
119
  # scoped
113
120
 
114
121
  should "do default weighting, scoped" do
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
  - Seamus Abshere
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-04-07 00:00:00 -04:00
20
+ date: 2010-05-17 00:00:00 -04:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency