Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d8ed8a7f
authored
Jul 12, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
remove dependent objects on destroy
parent
82bfc966
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
4 deletions
app/models/db.rb
app/models/db_folder.rb
spec/models/db_file_spec.rb
spec/models/db_folder_spec.rb
spec/models/db_spec.rb
app/models/db.rb
View file @
d8ed8a7f
...
@@ -2,7 +2,10 @@
...
@@ -2,7 +2,10 @@
# Database object
# Database object
class
Db
<
ActiveRecord
::
Base
class
Db
<
ActiveRecord
::
Base
belongs_to
:root_folder
,
foreign_key:
'db_folder_id'
,
class_name:
'DbFolder'
belongs_to
:root_folder
,
foreign_key:
'db_folder_id'
,
class_name:
'DbFolder'
,
dependent: :destroy
belongs_to
:nilm
belongs_to
:nilm
def
url
def
url
...
...
app/models/db_folder.rb
View file @
d8ed8a7f
...
@@ -4,8 +4,13 @@
...
@@ -4,8 +4,13 @@
# and one or more DbFolders as subfolders
# and one or more DbFolders as subfolders
class
DbFolder
<
ActiveRecord
::
Base
class
DbFolder
<
ActiveRecord
::
Base
belongs_to
:parent
,
class_name:
'DbFolder'
belongs_to
:parent
,
class_name:
'DbFolder'
has_many
:subfolders
,
class_name:
'DbFolder'
,
foreign_key:
'parent_id'
has_many
:subfolders
,
has_many
:db_files
class_name:
'DbFolder'
,
foreign_key:
'parent_id'
,
dependent: :destroy
has_many
:db_files
,
dependent: :destroy
def
self
.
defined_attributes
def
self
.
defined_attributes
[
:name
,
:description
,
:hidden
]
[
:name
,
:description
,
:hidden
]
...
...
spec/models/db_file_spec.rb
View file @
d8ed8a7f
...
@@ -11,6 +11,14 @@ RSpec.describe 'DbFile' do
...
@@ -11,6 +11,14 @@ RSpec.describe 'DbFile' do
specify
{
expect
(
db_file
).
to
respond_to
(
:hidden
)
}
specify
{
expect
(
db_file
).
to
respond_to
(
:hidden
)
}
end
end
it
'removes streams destroyed'
do
stream
=
DbStream
.
create
file
=
DbFile
.
create
file
.
db_streams
<<
stream
file
.
destroy
expect
(
DbStream
.
find_by_id
(
stream
.
id
)).
to
be
nil
end
describe
'remove'
do
describe
'remove'
do
let
(
:db_streams
)
{
FactoryGirl
.
build_list
(
:db_stream
,
5
)
}
let
(
:db_streams
)
{
FactoryGirl
.
build_list
(
:db_stream
,
5
)
}
let
(
:db_file
)
{
FactoryGirl
.
create
(
:db_file
)
}
let
(
:db_file
)
{
FactoryGirl
.
create
(
:db_file
)
}
...
@@ -31,4 +39,5 @@ RSpec.describe 'DbFile' do
...
@@ -31,4 +39,5 @@ RSpec.describe 'DbFile' do
expect
(
db_service
).
to
have_received
(
:remove_file
)
expect
(
db_service
).
to
have_received
(
:remove_file
)
end
end
end
end
end
end
spec/models/db_folder_spec.rb
View file @
d8ed8a7f
...
@@ -12,6 +12,23 @@ RSpec.describe 'DbFolder' do
...
@@ -12,6 +12,23 @@ RSpec.describe 'DbFolder' do
specify
{
expect
(
db_folder
).
to
respond_to
(
:hidden
)
}
specify
{
expect
(
db_folder
).
to
respond_to
(
:hidden
)
}
end
end
describe
'when destroyed'
do
before
(
:all
)
do
@folder
=
DbFolder
.
create
@subfolder
=
DbFolder
.
create
@file
=
DbFile
.
create
@folder
.
subfolders
<<
@subfolder
@folder
.
db_files
<<
@file
@folder
.
destroy
end
it
'removes subfolders'
do
expect
(
DbFolder
.
find_by_id
(
@subfolder
.
id
)).
to
be_nil
end
it
'removes subfiles'
do
expect
(
DbFile
.
find_by_id
(
@file
.
id
)).
to
be_nil
end
end
describe
'insert_file'
do
describe
'insert_file'
do
let
(
:db_folder
)
{
FactoryGirl
.
create
(
:db_folder
)
}
let
(
:db_folder
)
{
FactoryGirl
.
create
(
:db_folder
)
}
let
(
:new_file
)
{
FactoryGirl
.
create
(
:db_file
)
}
let
(
:new_file
)
{
FactoryGirl
.
create
(
:db_file
)
}
...
...
spec/models/db_spec.rb
View file @
d8ed8a7f
# frozen_string_literal: true
# frozen_string_literal: true
require
'rails_helper'
require
'rails_helper'
RSpec
.
describe
'Db
Stream
'
do
RSpec
.
describe
'Db'
do
describe
'object'
do
describe
'object'
do
let
(
:db
)
{
Db
.
new
}
let
(
:db
)
{
Db
.
new
}
specify
{
expect
(
db
).
to
respond_to
(
:url
)
}
specify
{
expect
(
db
).
to
respond_to
(
:url
)
}
specify
{
expect
(
db
).
to
respond_to
(
:root_folder
)
}
specify
{
expect
(
db
).
to
respond_to
(
:root_folder
)
}
end
end
it
'removes the root folder when destroyed'
do
root_folder
=
DbFolder
.
create
db
=
Db
.
create
(
root_folder:
root_folder
)
db
.
destroy
expect
(
DbFolder
.
find_by_id
(
root_folder
.
id
)).
to
be
nil
end
end
end
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