Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
weather-model
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
weather-model
Commits
fba839d2
Commit
fba839d2
authored
May 20, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix spec
parent
0672e8d1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
13 deletions
+17
-13
weather-model_spec.rb
spec/weather-model_spec.rb
+17
-13
No files found.
spec/weather-model_spec.rb
View file @
fba839d2
...
...
@@ -2,19 +2,23 @@ require "spec_helper"
require
'active_record'
require
"ohm"
include
WeatherModel
RSpec
.
describe
WeatherModel
do
include
WeatherModel
before
do
# start an ohm
WeatherModel
.
set_ohm
Redic
.
new
(
"redis://127.0.0.1:6379/5"
)
# run migration
Dir
[
File
.
dirname
(
__FILE__
)
+
'/../db/migrate/*.rb'
].
each
{
|
file
|
require
file
}
# drop table
FileUtils
.
rm
'weather-model-test.sqlite3'
ActiveRecord
::
Base
.
establish_connection
(
:adapter
=>
'sqlite3'
,
:database
=>
'weather-model-test.sqlite3'
)
ActiveRecord
::
Migration
[
5.0
].
subclasses
.
each
do
|
migrate
|
migrate
.
migrate
(
:up
)
migrate
.
migrate
(
:up
)
end
end
...
...
@@ -24,20 +28,20 @@ RSpec.describe WeatherModel do
describe
'test factory_girl'
do
before
do
@obj
=
create
(
:
forecast_shanghai_ten
)
@obj
=
create
(
:
city_forecast
)
end
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
it
'Forecast'
do
@expire
=
1
Forecast
::
ShanghaiTen
::
Ohm
.
expire
@expire
mysql_obj
=
Forecast
::
ShanghaiTen
.
create
({
date
time
:
'2017-05-16'
,
Forecast
::
CityForecast
::
Ohm
.
expire
@expire
mysql_obj
=
Forecast
::
CityForecast
.
create
({
date:
'2017-05-16'
,
cityname:
'shanghai'
,
temp_high:
'100'
,
temp_low:
'0'
,
...
...
@@ -46,15 +50,15 @@ RSpec.describe WeatherModel do
win_dir:
'东南西北风'
,
win_speed:
'1级'
,
})
expect
(
Forecast
::
ShanghaiTen
.
count
).
to
eq
(
1
)
expect
(
Forecast
::
ShanghaiTen
::
Ohm
.
all
.
count
).
to
eq
(
1
)
expect
(
Forecast
::
ShanghaiTen
::
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
.
count
).
to
eq
(
1
)
expect
(
Forecast
::
CityForecast
::
Ohm
.
all
.
count
).
to
eq
(
1
)
expect
(
Forecast
::
CityForecast
::
Ohm
.
all
.
first
.
temp_low
).
to
eq
(
mysql_obj
.
temp_low
.
to_s
)
expect
(
Forecast
::
CityForecast
::
Ohm
.
all
.
first
.
get_ttl
).
to
eq
(
@expire
)
# 'ohm 对象 同步 mysql对象更新'
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
expect
(
Forecast
::
ShanghaiTen
::
Ohm
.
all
.
count
).
to
eq
(
0
),
'TTL过期对象删除成功'
expect
(
Forecast
::
CityForecast
::
Ohm
.
all
.
count
).
to
eq
(
0
),
'TTL过期对象删除成功'
end
after
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment