Commit fba839d2 by ivan Lan

Fix spec

parent 0672e8d1
...@@ -2,13 +2,17 @@ require "spec_helper" ...@@ -2,13 +2,17 @@ require "spec_helper"
require 'active_record' require 'active_record'
require "ohm" require "ohm"
include WeatherModel
RSpec.describe WeatherModel do RSpec.describe WeatherModel do
include WeatherModel
before do before do
# start an ohm # start an ohm
WeatherModel.set_ohm Redic.new("redis://127.0.0.1:6379/5") WeatherModel.set_ohm Redic.new("redis://127.0.0.1:6379/5")
# run migration # run migration
Dir[File.dirname(__FILE__) + '/../db/migrate/*.rb'].each { |file| require file } Dir[File.dirname(__FILE__) + '/../db/migrate/*.rb'].each { |file| require file }
# drop table
FileUtils.rm 'weather-model-test.sqlite3'
ActiveRecord::Base.establish_connection( ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3', :adapter => 'sqlite3',
:database => 'weather-model-test.sqlite3' :database => 'weather-model-test.sqlite3'
...@@ -24,20 +28,20 @@ RSpec.describe WeatherModel do ...@@ -24,20 +28,20 @@ RSpec.describe WeatherModel do
describe 'test factory_girl' do describe 'test factory_girl' do
before do before do
@obj = create(:forecast_shanghai_ten) @obj = create(:city_forecast)
end end
it 'Test factory_girl' do it 'Test factory_girl' do
expect(@obj.class).to eq(Forecast::ShanghaiTen), 'factory_girl 生成成功' expect(@obj.class).to eq(Forecast::CityForecast), 'factory_girl 生成成功'
end end
end end
it 'Forecast' do it 'Forecast' do
@expire = 1 @expire = 1
Forecast::ShanghaiTen::Ohm.expire @expire Forecast::CityForecast::Ohm.expire @expire
mysql_obj = Forecast::ShanghaiTen.create({ mysql_obj = Forecast::CityForecast.create({
datetime: '2017-05-16', date: '2017-05-16',
cityname: 'shanghai', cityname: 'shanghai',
temp_high: '100', temp_high: '100',
temp_low: '0', temp_low: '0',
...@@ -46,15 +50,15 @@ RSpec.describe WeatherModel do ...@@ -46,15 +50,15 @@ RSpec.describe WeatherModel do
win_dir: '东南西北风', win_dir: '东南西北风',
win_speed: '1级', win_speed: '1级',
}) })
expect(Forecast::ShanghaiTen.count).to eq(1) expect(Forecast::CityForecast.count).to eq(1)
expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(1) expect(Forecast::CityForecast::Ohm.all.count).to eq(1)
expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq(mysql_obj.temp_low.to_s) expect(Forecast::CityForecast::Ohm.all.first.temp_low).to eq(mysql_obj.temp_low.to_s)
expect(Forecast::ShanghaiTen::Ohm.all.first.get_ttl).to eq(@expire) expect(Forecast::CityForecast::Ohm.all.first.get_ttl).to eq(@expire)
# 'ohm 对象 同步 mysql对象更新' # 'ohm 对象 同步 mysql对象更新'
mysql_obj.update(temp_low: 99) mysql_obj.update(temp_low: 99)
expect(Forecast::ShanghaiTen::Ohm.all.first.temp_low).to eq('99'), 'ohm 对象 同步 mysql对象更新' expect(Forecast::CityForecast::Ohm.all.first.temp_low).to eq('99'), 'ohm 对象 同步 mysql对象更新'
sleep 1.5 sleep 1.5
expect(Forecast::ShanghaiTen::Ohm.all.count).to eq(0), 'TTL过期对象删除成功' expect(Forecast::CityForecast::Ohm.all.count).to eq(0), 'TTL过期对象删除成功'
end end
after do after do
......
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