Skip to content

Commit

Permalink
adding a scope for arch
Browse files Browse the repository at this point in the history
  • Loading branch information
lsanchez-r7 committed Nov 30, 2016
1 parent b23c833 commit 2318b9c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
22 changes: 14 additions & 8 deletions app/models/mdm/module/detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ class Mdm::Module::Detail < ActiveRecord::Base
# Scopes
#

scope :module_app, ->(values) { where(Mdm::Module::Detail[:stance].matches_any(values)) }

scope :module_arch, ->(values) {
joins(Mdm::Module::Detail.join_association(:archs,Arel::Nodes::OuterJoin)).
where(Mdm::Module::Arch[:name].matches_any(values))
}

scope :module_author, ->(values) {
joins(Mdm::Module::Detail.join_association(:authors, Arel::Nodes::OuterJoin)).
where(
Expand Down Expand Up @@ -224,6 +231,11 @@ class Mdm::Module::Detail < ActiveRecord::Base
)
}

scope :module_ref, ->(values) {
joins(Mdm::Module::Detail.join_association(:refs, Arel::Nodes::OuterJoin)).
where(Mdm::Module::Ref[:name].matches_any(values))
}

scope :module_text, ->(values) {
joins(
Mdm::Module::Detail.join_association(:actions, Arel::Nodes::OuterJoin),
Expand All @@ -245,15 +257,9 @@ class Mdm::Module::Detail < ActiveRecord::Base
)))))))))
}

scope :module_type, ->(values) { where(Mdm::Module::Detail[:mtype].matches_any(values)) }

scope :module_app, ->(values) { where(Mdm::Module::Detail[:stance].matches_any(values)) }

scope :module_ref, ->(values) {
joins(Mdm::Module::Detail.join_association(:refs, Arel::Nodes::OuterJoin)).
where(Mdm::Module::Ref[:name].matches_any(values))
}

scope :module_type, ->(values) { where(Mdm::Module::Detail[:mtype].matches_any(values)) }

#
# Validations
#
Expand Down
47 changes: 29 additions & 18 deletions spec/app/models/mdm/module/detail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,25 @@

end

context '#module_app' do
it 'finds all modules with a stance matching "agg"' do
expect(Mdm::Module::Detail.module_app(['%agg%']).uniq).to contain_exactly(
@ms12_020,@ms08_067,@ms06_040,@cve_2010_0425)
end
it 'finds all modules with a stance matching "pass"' do
expect(Mdm::Module::Detail.module_app(['%pass%']).uniq).to contain_exactly(@cve_2012_0507)
end
end

context '#module_arch' do
it 'finds all modules with a stance matching "java"' do
expect(Mdm::Module::Detail.module_arch(['%java%']).uniq).to contain_exactly(@cve_2012_0507)
end
it 'finds all modules with a stance matching "pass"' do
expect(Mdm::Module::Detail.module_arch(['%pass%']).uniq).to contain_exactly(@cve_2012_0507)
end
end

context '#module_author' do
it 'finds all modules with author matching "Juan"' do
expect(Mdm::Module::Detail.module_author(['%juan%'])).to contain_exactly(@cve_2012_0507)
Expand Down Expand Up @@ -366,6 +385,16 @@
end
end

context 'module_ref' do
it 'finds all modules with a reff matching "CVE-2012"' do
expect(Mdm::Module::Detail.module_ref(['%CVE-2012%']).uniq).to contain_exactly(
@ms12_020,@cve_2012_0507)
end
it 'finds all modules with a reff matching "EDB"' do
expect(Mdm::Module::Detail.module_ref(['%EDB%']).uniq).to contain_exactly(@ms12_020)
end
end

context '#module_text' do
it 'finds all modules with a description matching "ConnectMCSPDU"' do
expect(Mdm::Module::Detail.module_text(['%ConnectMCSPDU%']).uniq).to contain_exactly(@ms12_020)
Expand Down Expand Up @@ -403,25 +432,7 @@
end
end

context 'module_app' do
it 'finds all modules with a stance matching "agg"' do
expect(Mdm::Module::Detail.module_app(['%agg%']).uniq).to contain_exactly(
@ms12_020,@ms08_067,@ms06_040,@cve_2010_0425)
end
it 'finds all modules with a stance matching "pass"' do
expect(Mdm::Module::Detail.module_app(['%pass%']).uniq).to contain_exactly(@cve_2012_0507)
end
end

context 'module_ref' do
it 'finds all modules with a reff matching "CVE-2012"' do
expect(Mdm::Module::Detail.module_ref(['%CVE-2012%']).uniq).to contain_exactly(
@ms12_020,@cve_2012_0507)
end
it 'finds all modules with a reff matching "EDB"' do
expect(Mdm::Module::Detail.module_ref(['%EDB%']).uniq).to contain_exactly(@ms12_020)
end
end
end

context 'validations' do
Expand Down

0 comments on commit 2318b9c

Please sign in to comment.