okei 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +61 -0
- data/CHANGELOG.rdoc +13 -0
- data/LICENSE.rdoc +21 -0
- data/README.rdoc +91 -0
- data/Rakefile +52 -0
- data/app/controllers/okei/api/v1/responder.rb +30 -0
- data/app/controllers/okei/api/v1/units_controller.rb +41 -0
- data/app/models/okei/line.rb +63 -0
- data/app/models/okei/unit.rb +17 -0
- data/app/models/okei/word.rb +26 -0
- data/app/models/okei/words.rb +40 -0
- data/app/use_cases/okei/find_unit.rb +65 -0
- data/app/use_cases/okei/get_unit.rb +50 -0
- data/app/use_cases/okei/get_units.rb +45 -0
- data/app/views/okei/api/v1/units/_unit.json.jbuilder +6 -0
- data/app/views/okei/api/v1/units/errors.json.jbuilder +5 -0
- data/app/views/okei/api/v1/units/index.json.jbuilder +5 -0
- data/app/views/okei/api/v1/units/show.json.jbuilder +3 -0
- data/config/locales/ru.yml +12 -0
- data/config/routes.rb +12 -0
- data/db/migrate/20141004212500_create_okei_units.rb +20 -0
- data/db/migrate/20141004212501_populate_okei_units.rb +14 -0
- data/db/migrate/20141004212502_create_okei_words.rb +11 -0
- data/db/migrate/20141004212503_populate_okei_words.rb +15 -0
- data/db/seeds/units.json +4534 -0
- data/db/seeds/words.json +2462 -0
- data/lib/okei.rb +7 -0
- data/lib/okei/engine.rb +12 -0
- data/lib/okei/version.rb +4 -0
- data/lib/tasks/okei_tasks.rake +56 -0
- data/spec/controllers/okei/api/v1/responder_spec.rb +69 -0
- data/spec/controllers/okei/api/v1/units_controller_spec.rb +88 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +13 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/schema.rb +39 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +49831 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/examples/json_schemas/error.json +14 -0
- data/spec/examples/json_schemas/get_errors.json +18 -0
- data/spec/examples/json_schemas/get_unit.json +13 -0
- data/spec/examples/json_schemas/get_units.json +17 -0
- data/spec/examples/json_schemas/unit.json +20 -0
- data/spec/factories/units.rb +18 -0
- data/spec/factories/words.rb +7 -0
- data/spec/models/okei/line_spec.rb +61 -0
- data/spec/models/okei/unit_spec.rb +170 -0
- data/spec/models/okei/word_spec.rb +75 -0
- data/spec/models/okei/words_spec.rb +64 -0
- data/spec/requests/okei/api/v1/find_unit_spec.rb +65 -0
- data/spec/requests/okei/api/v1/get_unit_spec.rb +57 -0
- data/spec/requests/okei/api/v1/get_units_spec.rb +64 -0
- data/spec/routing/okei/api/v1/units_routing_spec.rb +56 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/initializers/caching.rb +20 -0
- data/spec/support/initializers/coveralls.rb +4 -0
- data/spec/support/initializers/database_cleaner.rb +24 -0
- data/spec/support/initializers/factory_girl.rb +6 -0
- data/spec/support/initializers/factory_girl_rails.rb +1 -0
- data/spec/support/initializers/focus.rb +5 -0
- data/spec/support/initializers/garbage_collection.rb +11 -0
- data/spec/support/initializers/i18n.rb +1 -0
- data/spec/support/initializers/migrations.rb +3 -0
- data/spec/support/initializers/rails.rb +6 -0
- data/spec/support/initializers/random_order.rb +4 -0
- data/spec/support/initializers/rspec.rb +10 -0
- data/spec/support/initializers/timecop.rb +1 -0
- data/spec/support/matchers/controllers.rb +14 -0
- data/spec/support/matchers/json_schema.rb +10 -0
- data/spec/use_cases/okei/find_unit_spec.rb +77 -0
- data/spec/use_cases/okei/get_unit_spec.rb +64 -0
- data/spec/use_cases/okei/get_units_spec.rb +65 -0
- data/spec/views/okei/api/v1/units/_unit.json_spec.rb +24 -0
- metadata +400 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// JSON schema for an error message
|
2
|
+
{
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
|
5
|
+
"type": "object",
|
6
|
+
|
7
|
+
"properties": {
|
8
|
+
"type": { "type": "string", "enum": ["error"] },
|
9
|
+
"text": { "type": "string", "minLength": 1 }
|
10
|
+
},
|
11
|
+
|
12
|
+
"additionalProperties": false,
|
13
|
+
"required": ["type", "text"]
|
14
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// JSON schema for getting an error messages
|
2
|
+
{
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
|
5
|
+
"type": "object",
|
6
|
+
|
7
|
+
"properties": {
|
8
|
+
"messages": {
|
9
|
+
"type": "array",
|
10
|
+
"items": { "$ref": "error.json" },
|
11
|
+
"minimumUnits": 1,
|
12
|
+
"unique": true
|
13
|
+
}
|
14
|
+
},
|
15
|
+
|
16
|
+
"additionalProperties": false,
|
17
|
+
"required": ["messages"]
|
18
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// JSON schema for getting a list of units
|
2
|
+
{
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
|
5
|
+
"type": "object",
|
6
|
+
|
7
|
+
"properties": {
|
8
|
+
"units": {
|
9
|
+
"type": "array",
|
10
|
+
"items": { "$ref": "unit.json" },
|
11
|
+
"unique": true
|
12
|
+
}
|
13
|
+
},
|
14
|
+
|
15
|
+
"additionalProperties": false,
|
16
|
+
"required": ["units"]
|
17
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
// JSON schema for the unit
|
2
|
+
{
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
|
5
|
+
"type": "object",
|
6
|
+
|
7
|
+
"properties": {
|
8
|
+
"uuid": { "type": "string", "format": "^(a-f|\\d|-){36}$" },
|
9
|
+
"name": { "type": "string", "minLength": 1 },
|
10
|
+
"code": { "type": "string", "minLength": 1 },
|
11
|
+
"num": { "type": "string", "format": "^(\\d){3}$" },
|
12
|
+
"int_code": { "type": "string", "format": "^(A-Z){2,4}$" },
|
13
|
+
"base": { "type": "string", "minLength": 1 },
|
14
|
+
"factor": { "type": "number", "minimum": 0.0, "exclusiveMinimum": true },
|
15
|
+
"measure": { "type": "string", "minimum": 1 }
|
16
|
+
},
|
17
|
+
|
18
|
+
"additionalProperties": false,
|
19
|
+
"required": ["uuid", "name", "code", "base", "factor", "measure"]
|
20
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "securerandom"
|
3
|
+
|
4
|
+
FactoryGirl.define do
|
5
|
+
|
6
|
+
chars = ("A".."Z").to_a
|
7
|
+
|
8
|
+
factory :unit, class: Okei::Unit do
|
9
|
+
uuid { SecureRandom.uuid }
|
10
|
+
sequence(:name) { |n| "Единица #{ n }" }
|
11
|
+
sequence(:code) { |n| "ЕИ #{ n }" }
|
12
|
+
sequence(:num) { |n| format "%03d", (n + 1) % 999 }
|
13
|
+
sequence(:int_code) { |n| chars[n % 25] + chars[n % 24] + chars[n % 23] }
|
14
|
+
base { "М" }
|
15
|
+
factor { rand(0.01..1000.0).round(2) }
|
16
|
+
measure { "Длина" }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Okei
|
5
|
+
describe Line do
|
6
|
+
|
7
|
+
describe ".new" do
|
8
|
+
|
9
|
+
# ========================================================================
|
10
|
+
# Matchers
|
11
|
+
# ========================================================================
|
12
|
+
|
13
|
+
RSpec::Matchers.define :turn_to do |line|
|
14
|
+
match do |str|
|
15
|
+
expect(Line.new str).to eq line
|
16
|
+
end
|
17
|
+
failure_message do |str|
|
18
|
+
"#{ str } should turn to #{ line }. #{ Line.new str } given."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# ========================================================================
|
23
|
+
# Tests
|
24
|
+
# ========================================================================
|
25
|
+
|
26
|
+
it "returns a string" do
|
27
|
+
expect(Line.new).to be_kind_of String
|
28
|
+
end
|
29
|
+
|
30
|
+
specify { expect("усл метр/сек^2").to turn_to "УСЛ МЕТР/СЕК ^ 2" }
|
31
|
+
specify { expect("100 М").to turn_to "100 М" }
|
32
|
+
specify { expect("0,1КМ").to turn_to "0.1КМ" }
|
33
|
+
specify { expect("М.1").to turn_to "М 1" }
|
34
|
+
specify { expect("М2").to turn_to "М ^ 2" }
|
35
|
+
specify { expect("М 2").to turn_to "М ^ 2" }
|
36
|
+
specify { expect("М.2").to turn_to "М ^ 2" }
|
37
|
+
specify { expect("М. 2").to turn_to "М ^ 2" }
|
38
|
+
specify { expect("М^2").to turn_to "М ^ 2" }
|
39
|
+
specify { expect("М3").to turn_to "М ^ 3" }
|
40
|
+
specify { expect("М 3").to turn_to "М ^ 3" }
|
41
|
+
specify { expect("М.3").to turn_to "М ^ 3" }
|
42
|
+
specify { expect("М. 3").to turn_to "М ^ 3" }
|
43
|
+
specify { expect("М^3").to turn_to "М ^ 3" }
|
44
|
+
specify { expect("М.4").to turn_to "М 4" }
|
45
|
+
specify { expect("ТЫС. Ч").to turn_to "ТЫС Ч" }
|
46
|
+
specify { expect("ТЫС. Ч.").to turn_to "ТЫС Ч" }
|
47
|
+
specify { expect(".ТЫС .Ч").to turn_to "ТЫС Ч" }
|
48
|
+
specify { expect("в 20-фут.экв.").to turn_to "В 20 ФУТ ЭКВ" }
|
49
|
+
specify { expect("METP B ЧAC").to turn_to "МЕТР В ЧАС" }
|
50
|
+
specify { expect("ГЕКТОЛИТР").to turn_to "ГЕКТО ^ ЛИТР" }
|
51
|
+
specify { expect("КИЛОЛИТР").to turn_to "КИЛО ^ ЛИТР" }
|
52
|
+
specify { expect("МИЛЛИЛИТР").to turn_to "МИЛЛИ ^ ЛИТР" }
|
53
|
+
specify { expect("МЕГАЛИТР").to turn_to "МЕГА ^ ЛИТР" }
|
54
|
+
specify { expect("САНТИЛИТР").to turn_to "САНТИ ^ ЛИТР" }
|
55
|
+
specify { expect("МИКРОЛИТР").to turn_to "МИКРО ^ ЛИТР" }
|
56
|
+
specify { expect("ТЕРАЛИТР").to turn_to "ТЕРА ^ ЛИТР" }
|
57
|
+
specify { expect("НАНОЛИТР").to turn_to "НАНО ^ ЛИТР" }
|
58
|
+
specify { expect("40%-НОГО СПИРТА").to turn_to "40% СПИРТА" }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Okei
|
5
|
+
describe Unit do
|
6
|
+
|
7
|
+
let!(:unit) { Unit.new }
|
8
|
+
|
9
|
+
describe "#uuid=" do
|
10
|
+
|
11
|
+
it "assigns a uuid" do
|
12
|
+
value = "48f53a7c-726f-4ec1-9b83-a12b247844a6"
|
13
|
+
expect { unit.uuid = value }.to change { unit.uuid }.to value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#name=" do
|
18
|
+
|
19
|
+
it "assigns a name" do
|
20
|
+
value = "Морская миля (1852 м)"
|
21
|
+
expect { unit.name = value }.to change { unit.name }.to value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#code=" do
|
26
|
+
|
27
|
+
it "assigns a code" do
|
28
|
+
value = "МИЛЬ"
|
29
|
+
expect { unit.code = value }.to change { unit.code }.to value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#num=" do
|
34
|
+
|
35
|
+
it "assigns a num" do
|
36
|
+
value = "049"
|
37
|
+
expect { unit.num = value }.to change { unit.num }.to value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#int_code=" do
|
42
|
+
|
43
|
+
it "assigns an int_code" do
|
44
|
+
value = "NMI"
|
45
|
+
expect { unit.int_code = value }.to change { unit.int_code }.to value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#base=" do
|
50
|
+
|
51
|
+
it "assigns a base" do
|
52
|
+
value = "M"
|
53
|
+
expect { unit.base = value }.to change { unit.base }.to value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#factor=" do
|
58
|
+
|
59
|
+
it "assigns a factor" do
|
60
|
+
value = 1852.0
|
61
|
+
expect { unit.factor = value }.to change { unit.factor }.to value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#measure=" do
|
66
|
+
|
67
|
+
it "assigns a measure" do
|
68
|
+
value = "Длина"
|
69
|
+
expect { unit.measure = value }.to change { unit.measure }.to value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#valid?" do
|
74
|
+
|
75
|
+
let!(:unit) { build :unit }
|
76
|
+
before { expect(unit).to be_valid }
|
77
|
+
|
78
|
+
it "fails when a uuid is absent" do
|
79
|
+
unit.uuid = nil
|
80
|
+
expect(unit).not_to be_valid
|
81
|
+
end
|
82
|
+
|
83
|
+
it "fails when uuid has a wrong format" do
|
84
|
+
%w(
|
85
|
+
48f53a7c-726f-4ec1-9b83-a12b2478446
|
86
|
+
48f53a7c-726f-4ec1-9b83-a12b2478446g
|
87
|
+
48f53a7c-726f-4ec19-b83-a12b2478446g
|
88
|
+
48f53a7c-726f-4ec1-9b83-a12b2478446ee
|
89
|
+
).each do |value|
|
90
|
+
unit.uuid = value
|
91
|
+
expect(unit).not_to be_valid
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "fails when a uuid is already taken" do
|
96
|
+
create :unit, uuid: unit.uuid
|
97
|
+
expect(unit).not_to be_valid
|
98
|
+
end
|
99
|
+
|
100
|
+
it "fails when a name is absent" do
|
101
|
+
unit.name = nil
|
102
|
+
expect(unit).not_to be_valid
|
103
|
+
end
|
104
|
+
|
105
|
+
it "fails when a name is already taken" do
|
106
|
+
create :unit, name: unit.name
|
107
|
+
expect(unit).not_to be_valid
|
108
|
+
end
|
109
|
+
|
110
|
+
it "fails when a code is absent" do
|
111
|
+
unit.code = nil
|
112
|
+
expect(unit).not_to be_valid
|
113
|
+
end
|
114
|
+
|
115
|
+
it "fails when a code is already taken" do
|
116
|
+
create :unit, code: unit.code
|
117
|
+
expect(unit).not_to be_valid
|
118
|
+
end
|
119
|
+
|
120
|
+
it "passes when a num is absent" do
|
121
|
+
unit.num = nil
|
122
|
+
expect(unit).to be_valid
|
123
|
+
end
|
124
|
+
|
125
|
+
it "fails when a num has a wrong format" do
|
126
|
+
%w(99 1000 abc).each do |value|
|
127
|
+
unit.num = value
|
128
|
+
expect(unit).not_to be_valid
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "passes when a num is already taken" do
|
133
|
+
create :unit, num: unit.num
|
134
|
+
expect(unit).to be_valid
|
135
|
+
end
|
136
|
+
|
137
|
+
it "passes when an int_code is absent" do
|
138
|
+
unit.int_code = nil
|
139
|
+
expect(unit).to be_valid
|
140
|
+
end
|
141
|
+
|
142
|
+
it "passes when an int_code is already taken" do
|
143
|
+
create :unit, int_code: unit.int_code
|
144
|
+
expect(unit).to be_valid
|
145
|
+
end
|
146
|
+
|
147
|
+
it "fails when a base is absent" do
|
148
|
+
unit.base = nil
|
149
|
+
expect(unit).not_to be_valid
|
150
|
+
end
|
151
|
+
|
152
|
+
it "fails when a factor is absent" do
|
153
|
+
unit.factor = nil
|
154
|
+
expect(unit).not_to be_valid
|
155
|
+
end
|
156
|
+
|
157
|
+
it "fails when a factor is non-positive" do
|
158
|
+
[-1.0, 0.0].each do |value|
|
159
|
+
unit.factor = value
|
160
|
+
expect(unit).not_to be_valid
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it "fails when a measure is absent" do
|
165
|
+
unit.measure = nil
|
166
|
+
expect(unit).not_to be_valid
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|