Commit 3e58dcdb by ivan Lan

Add test to all source data

parent 139ef81e
...@@ -15,4 +15,3 @@ class CreateAqiForecasts < ActiveRecord::Migration[5.0] ...@@ -15,4 +15,3 @@ class CreateAqiForecasts < ActiveRecord::Migration[5.0]
drop_table :aqi_forecasts drop_table :aqi_forecasts
end end
end end
class CreateRealtimeAqi < ActiveRecord::Migration[5.0]
def up
create_table :realtime_aqi do |t|
t.datetime :datetime
t.integer :aqi
t.string :level
t.string :pripoll
t.string :content
t.string :measure
t.timestamps
end
add_index :realtime_aqi, :datetime
end
def down
drop_table :realtime_aqi
end
end
...@@ -51,5 +51,38 @@ module WeatherModel ...@@ -51,5 +51,38 @@ module WeatherModel
] ]
} }
} }
RealtimeAqi =
{
sort: 'Aqi',
table_name: :realtime_aqi,
schema: {
datetime: :datetime,
aqi: :string,
level: :string,
pripoll: :string,
content: :string,
measure: :string,
},
options: {
index: %i[datetime],
expire: 3 * 24 * 60 * 60,
unique: nil,
belongs_to: nil,
has_many: nil,
json_column: :msg
},
factory_name: :realtime_aqi,
factory: {
datetime: Time.parse('2011-11-11 11:11'),
aqi: '54',
level: '良',
pripoll: 'PM10',
msg: {
content: '空气质量可接受,但某些污染物可能对极少数异常敏感人群健康有较弱影响。',
measure: '建议措施极少数异常敏感人群应减少户外活动。'
}
}
}
end end
end end
module WeatherModel module WeatherModel
module SourceSchema module SourceSchema
TenMins = AutoStationTenMins =
{ {
sort: 'AutoStation', sort: 'AutoStation',
table_name: :auto_stations_ten_mins, table_name: :auto_station_ten_mins,
schema: { schema: {
datetime: :datetime, datetime: :datetime,
sitenumber: :string, sitenumber: :string,
......
...@@ -84,6 +84,15 @@ RSpec.describe WeatherModel do ...@@ -84,6 +84,15 @@ RSpec.describe WeatherModel do
expect(Aqi::AqiForecast::Ohm.all.first.list.class).to eq(Array), 'Ohm json_column 正常' expect(Aqi::AqiForecast::Ohm.all.first.list.class).to eq(Array), 'Ohm json_column 正常'
end end
it 'Test all source data' do
[
Forecast::CityForecast,
AutoStation::AutoStationTenMins,
Aqi::AqiForecast,
Aqi::RealtimeAqi
].each { |source| source.all; source.const_get('Ohm').all }
end
after do after do
ActiveRecord::Migration[5.0].subclasses.each do |migrate| ActiveRecord::Migration[5.0].subclasses.each do |migrate|
migrate.migrate(:down) migrate.migrate(:down)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment