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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
weather-model_spec.rb
spec/weather-model_spec.rb
+16
-12
No files found.
spec/weather-model_spec.rb
View file @
fba839d2
...
@@ -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
({
date
time
:
'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
...
...
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