citier4 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/citier4/acts_as_citier4.rb +95 -0
- data/lib/citier4/child_instance_methods.rb +111 -0
- data/lib/citier4/core_ext.rb +118 -0
- data/lib/citier4/instance_methods.rb +41 -0
- data/lib/citier4/relation_methods.rb +139 -0
- data/lib/citier4/root_class_methods.rb +36 -0
- data/lib/citier4/root_instance_methods.rb +47 -0
- data/lib/citier4/version.rb +3 -0
- data/lib/citier4.rb +34 -0
- data/lib/tasks/citier4_tasks.rake +4 -0
- data/test/acts_as_citier4_test.rb +10 -0
- data/test/child_instance_methods_test.rb +70 -0
- data/test/citier4_test.rb +7 -0
- data/test/core_ext_test.rb +7 -0
- data/test/deleting_methods_test.rb +101 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/animal.rb +16 -0
- data/test/dummy/app/models/bidule.rb +2 -0
- data/test/dummy/app/models/book.rb +7 -0
- data/test/dummy/app/models/dictionary.rb +3 -0
- data/test/dummy/app/models/fiction.rb +3 -0
- data/test/dummy/app/models/product.rb +8 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20141228200436_create_products.rb +10 -0
- data/test/dummy/db/migrate/20141228200756_create_books.rb +17 -0
- data/test/dummy/db/migrate/20150101181703_create_dictionaries.rb +16 -0
- data/test/dummy/db/migrate/20150101181916_create_fictions.rb +14 -0
- data/test/dummy/db/migrate/20150102200342_create_bidules.rb +9 -0
- data/test/dummy/db/migrate/20150102200786_create_animals.rb +10 -0
- data/test/dummy/db/schema.rb +81 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +2695 -0
- data/test/dummy/log/test.log +152338 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/bidules.yml +7 -0
- data/test/dummy/test/fixtures/books.yml +9 -0
- data/test/dummy/test/fixtures/dictionaries.yml +7 -0
- data/test/dummy/test/fixtures/fictions.yml +7 -0
- data/test/dummy/test/fixtures/products.yml +7 -0
- data/test/dummy/test/models/bidule_test.rb +7 -0
- data/test/dummy/test/models/book_test.rb +7 -0
- data/test/dummy/test/models/dictionary_test.rb +7 -0
- data/test/dummy/test/models/fiction_test.rb +7 -0
- data/test/dummy/test/models/product_test.rb +7 -0
- data/test/model_test.rb +34 -0
- data/test/retrieving_methods_test.rb +153 -0
- data/test/root_instance_methods_test.rb +27 -0
- data/test/test_helper.rb +60 -0
- metadata +227 -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
|
data/test/model_test.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class Model < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
@product = Product.create( name: "Un Produit")
|
|
8
|
+
@book = Book.create( name: "Mon Livre", author: "Laurent")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test "product valid?" do
|
|
12
|
+
assert @product.valid?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test "poduct name sould be present" do
|
|
16
|
+
@product.name =""
|
|
17
|
+
assert_not @product.valid?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "book valid?" do
|
|
21
|
+
assert @book.valid?
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test "book name sould be present" do
|
|
25
|
+
@book.name =""
|
|
26
|
+
assert_not @book.valid?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "book author sould be present" do
|
|
30
|
+
@book.author =""
|
|
31
|
+
assert_not @book.valid?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
# http://api.rubyonrails.org/classes/ActiveRecord/Relation.html
|
|
4
|
+
|
|
5
|
+
class RootInstanceMethods < ActiveSupport::TestCase
|
|
6
|
+
|
|
7
|
+
def setup
|
|
8
|
+
populate
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# bind
|
|
12
|
+
# create_with
|
|
13
|
+
# distinct
|
|
14
|
+
# eager_load
|
|
15
|
+
# extending
|
|
16
|
+
# from
|
|
17
|
+
# group
|
|
18
|
+
# having
|
|
19
|
+
# includes
|
|
20
|
+
# joins
|
|
21
|
+
# limit
|
|
22
|
+
# lock
|
|
23
|
+
# none
|
|
24
|
+
# offset
|
|
25
|
+
# order
|
|
26
|
+
# preload
|
|
27
|
+
# readonly
|
|
28
|
+
# references
|
|
29
|
+
# reorder
|
|
30
|
+
# reverse_order
|
|
31
|
+
# select
|
|
32
|
+
# uniq
|
|
33
|
+
# where
|
|
34
|
+
|
|
35
|
+
test "find_by in root or child " do
|
|
36
|
+
assert_equal Product.count, 12
|
|
37
|
+
# product = Product.find_by( name: "UnLivre")
|
|
38
|
+
p = Product.find_by(name: "Dictionary2")
|
|
39
|
+
d = Dictionary.find_by( name: "Dictionary2")
|
|
40
|
+
b = Book.find_by(name: "Dictionary2")
|
|
41
|
+
assert p
|
|
42
|
+
assert d
|
|
43
|
+
assert b
|
|
44
|
+
assert_equal p, d
|
|
45
|
+
assert_equal p, b
|
|
46
|
+
|
|
47
|
+
# assert_not Product.find_by(author: "Laurent")
|
|
48
|
+
# comment tester qu'un code doit faire faux ? assert_raises ne marche pas, car pas une exception
|
|
49
|
+
b1 = Book.find_by(author: "Laurent")
|
|
50
|
+
assert_equal p, b1
|
|
51
|
+
d1 = Dictionary.find_by(author: "Laurent")
|
|
52
|
+
assert_equal p, d1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test "find with ID in root or child " do
|
|
56
|
+
assert_equal Product.count, 12
|
|
57
|
+
# product = Product.find_by( name: "UnLivre")
|
|
58
|
+
product = Product.find_by(name: "Dictionary2")
|
|
59
|
+
p = Product.find(product.id)
|
|
60
|
+
d = Dictionary.find(product.id)
|
|
61
|
+
b = Book.find(product.id)
|
|
62
|
+
assert p
|
|
63
|
+
assert d
|
|
64
|
+
assert b
|
|
65
|
+
assert_equal product, p
|
|
66
|
+
assert_equal product, d
|
|
67
|
+
assert_equal product, b
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
test "take for root or child " do
|
|
71
|
+
assert_equal Product.count, 12
|
|
72
|
+
assert_equal Book.count, 9
|
|
73
|
+
assert_equal Dictionary.count, 3
|
|
74
|
+
assert_equal Fiction.count, 3
|
|
75
|
+
|
|
76
|
+
assert Product.take
|
|
77
|
+
assert Product.take(4).count == 4
|
|
78
|
+
assert Product.take(12).count == 12
|
|
79
|
+
assert Product.take(13).count == 12
|
|
80
|
+
|
|
81
|
+
assert Book.take
|
|
82
|
+
assert Book.take(3).count == 3
|
|
83
|
+
assert Book.take(10).count == 9
|
|
84
|
+
|
|
85
|
+
assert Fiction.take
|
|
86
|
+
assert Fiction.take(3).count == 3
|
|
87
|
+
assert Fiction.take(10).count == 3
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
test "first for root or child " do
|
|
92
|
+
assert_equal Product.count, 12
|
|
93
|
+
|
|
94
|
+
assert Product.first
|
|
95
|
+
assert Book.first
|
|
96
|
+
assert Fiction.first
|
|
97
|
+
assert Dictionary.first
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
test "last for root or child " do
|
|
102
|
+
assert_equal Product.count, 12
|
|
103
|
+
|
|
104
|
+
assert Product.last
|
|
105
|
+
assert Book.last
|
|
106
|
+
assert Fiction.last
|
|
107
|
+
assert Dictionary.last
|
|
108
|
+
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
test "find_each for root or child " do
|
|
112
|
+
assert_equal Product.count, 12
|
|
113
|
+
n = 0
|
|
114
|
+
Product.find_each do | product |
|
|
115
|
+
puts product.name
|
|
116
|
+
n+=1
|
|
117
|
+
end
|
|
118
|
+
assert_equal n, 12
|
|
119
|
+
n = 0
|
|
120
|
+
Book.find_each do | book |
|
|
121
|
+
puts book.author
|
|
122
|
+
n+=1
|
|
123
|
+
end
|
|
124
|
+
assert_equal n, 9
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
test "find_in_batches for root or child " do
|
|
128
|
+
assert_equal Product.count, 12
|
|
129
|
+
|
|
130
|
+
Product.find_in_batches do | products |
|
|
131
|
+
products.each do | product|
|
|
132
|
+
puts product.name
|
|
133
|
+
end
|
|
134
|
+
assert_equal products.count, 12
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
Book.find_in_batches do | books |
|
|
138
|
+
books.each do | book |
|
|
139
|
+
puts book.author
|
|
140
|
+
end
|
|
141
|
+
assert_equal books.count, 9
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
test "where for root or child " do
|
|
146
|
+
assert_equal Product.count, 12
|
|
147
|
+
|
|
148
|
+
books = Product.where(type: :Book)
|
|
149
|
+
assert_equal books.count, 3 # WARNING. Here it's exact Book (so 3)
|
|
150
|
+
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class RootInstanceMethods < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
test "product instance is root" do
|
|
7
|
+
assert Product.new.is_root?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test "herited prodcut class instance is not root" do
|
|
11
|
+
class Something < Product
|
|
12
|
+
end
|
|
13
|
+
assert_not Something.new.is_root?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "delete all" do
|
|
17
|
+
Product.delete_all
|
|
18
|
+
assert_equal Product.count, 0
|
|
19
|
+
(:a..:x).each do |lettre|
|
|
20
|
+
Product.create(name: lettre)
|
|
21
|
+
end
|
|
22
|
+
assert_equal (:a..:x).count, Product.count
|
|
23
|
+
Product.delete_all
|
|
24
|
+
assert_equal Product.count, 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Configure Rails Environment
|
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
|
3
|
+
|
|
4
|
+
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
|
5
|
+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
|
6
|
+
require "rails/test_help"
|
|
7
|
+
|
|
8
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
9
|
+
|
|
10
|
+
# Load support files
|
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
12
|
+
|
|
13
|
+
# Load fixtures from the engine
|
|
14
|
+
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
|
15
|
+
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def populate
|
|
19
|
+
|
|
20
|
+
Book.create( name: "Livre1", author: "Inconnu1")
|
|
21
|
+
Product.create( name: "Product1")
|
|
22
|
+
Dictionary.create(name:"Dictionary1", author:"Aucun", language: "French")
|
|
23
|
+
Fiction.create(name:"Fiction1", author:"Aucun", story: "A good story")
|
|
24
|
+
Book.create( name: "Livre3", author: "Inconnu1")
|
|
25
|
+
Product.create( name: "Product2")
|
|
26
|
+
Dictionary.create(name:"Dictionary2", author:"Laurent", language: "French")
|
|
27
|
+
Fiction.create(name:"Fiction2", author:"Aucun", story: "A good story")
|
|
28
|
+
Book.create( name: "Livre3", author: "Inconnu1")
|
|
29
|
+
Product.create( name: "Product3")
|
|
30
|
+
Dictionary.create(name:"Dictionary3", author:"Aucun", language: "French")
|
|
31
|
+
Fiction.create(name:"Fiction3", author:"Aucun", story: "A good story")
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# return the number of record in real table (not view)
|
|
36
|
+
def citier_count(id)
|
|
37
|
+
connection = ActiveRecord::Base.connection
|
|
38
|
+
count = 0
|
|
39
|
+
count += connection.execute("SELECT COUNT(*) FROM products WHERE id = #{id}")[0][0]
|
|
40
|
+
count += connection.execute("SELECT COUNT(*) FROM books WHERE id = #{id}")[0][0]
|
|
41
|
+
count += connection.execute("SELECT COUNT(*) FROM dictionaries WHERE id = #{id}")[0][0]
|
|
42
|
+
count += connection.execute("SELECT COUNT(*) FROM fictions WHERE id = #{id}")[0][0]
|
|
43
|
+
return count
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def data_base_is_clean?(id)
|
|
47
|
+
citier_count(id)==0
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def delete_all
|
|
51
|
+
connection = ActiveRecord::Base.connection
|
|
52
|
+
connection.execute("DELETE FROM products")
|
|
53
|
+
connection.execute("DELETE FROM books")
|
|
54
|
+
connection.execute("DELETE FROM dictionaries")
|
|
55
|
+
connection.execute("DELETE FROM fictions")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|