summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/reference_parser
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/banzai/reference_parser')
-rw-r--r--spec/lib/banzai/reference_parser/base_parser_spec.rb110
-rw-r--r--spec/lib/banzai/reference_parser/commit_parser_spec.rb32
-rw-r--r--spec/lib/banzai/reference_parser/commit_range_parser_spec.rb24
-rw-r--r--spec/lib/banzai/reference_parser/issue_parser_spec.rb12
-rw-r--r--spec/lib/banzai/reference_parser/user_parser_spec.rb24
5 files changed, 101 insertions, 101 deletions
diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb
index 9126afb0693..aa127f0179d 100644
--- a/spec/lib/banzai/reference_parser/base_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb
@@ -54,8 +54,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
describe '#referenced_by' do
context 'when references_relation is implemented' do
it 'returns a collection of objects' do
- links = Nokogiri::HTML.fragment("<a data-foo='#{user.id}'></a>")
- .children
+ links = Nokogiri::HTML.fragment("<a data-foo='#{user.id}'></a>").
+ children
expect(subject).to receive(:references_relation).and_return(User)
expect(subject.referenced_by(links)).to eq([user])
@@ -66,8 +66,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
it 'raises NotImplementedError' do
links = Nokogiri::HTML.fragment('<a data-foo="1"></a>').children
- expect { subject.referenced_by(links) }
- .to raise_error(NotImplementedError)
+ expect { subject.referenced_by(links) }.
+ to raise_error(NotImplementedError)
end
end
end
@@ -80,8 +80,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
describe '#gather_attributes_per_project' do
it 'returns a Hash containing attribute values per project' do
- link = Nokogiri::HTML.fragment('<a data-project="1" data-foo="2"></a>')
- .children[0]
+ link = Nokogiri::HTML.fragment('<a data-project="1" data-foo="2"></a>').
+ children[0]
hash = subject.gather_attributes_per_project([link], 'data-foo')
@@ -95,9 +95,9 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
it 'returns a Hash grouping objects per ID' do
nodes = [double(:node)]
- expect(subject).to receive(:unique_attribute_values)
- .with(nodes, 'data-user')
- .and_return([user.id])
+ expect(subject).to receive(:unique_attribute_values).
+ with(nodes, 'data-user').
+ and_return([user.id])
hash = subject.grouped_objects_for_nodes(nodes, User, 'data-user')
@@ -113,15 +113,15 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
it 'returns an Array of unique values' do
link = double(:link)
- expect(link).to receive(:has_attribute?)
- .with('data-foo')
- .twice
- .and_return(true)
+ expect(link).to receive(:has_attribute?).
+ with('data-foo').
+ twice.
+ and_return(true)
- expect(link).to receive(:attr)
- .with('data-foo')
- .twice
- .and_return('1')
+ expect(link).to receive(:attr).
+ with('data-foo').
+ twice.
+ and_return('1')
nodes = [link, link]
@@ -138,9 +138,9 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
instance = dummy.new(project, user)
document = Nokogiri::HTML.fragment('<a class="gfm"></a><a class="gfm" data-reference-type="test"></a>')
- expect(instance).to receive(:gather_references)
- .with([document.children[1]])
- .and_return([user])
+ expect(instance).to receive(:gather_references).
+ with([document.children[1]]).
+ and_return([user])
expect(instance.process([document])).to eq([user])
end
@@ -150,9 +150,9 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
let(:link) { double(:link) }
it 'does not process links a user can not reference' do
- expect(subject).to receive(:nodes_user_can_reference)
- .with(user, [link])
- .and_return([])
+ expect(subject).to receive(:nodes_user_can_reference).
+ with(user, [link]).
+ and_return([])
expect(subject).to receive(:referenced_by).with([])
@@ -160,13 +160,13 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
end
it 'does not process links a user can not see' do
- expect(subject).to receive(:nodes_user_can_reference)
- .with(user, [link])
- .and_return([link])
+ expect(subject).to receive(:nodes_user_can_reference).
+ with(user, [link]).
+ and_return([link])
- expect(subject).to receive(:nodes_visible_to_user)
- .with(user, [link])
- .and_return([])
+ expect(subject).to receive(:nodes_visible_to_user).
+ with(user, [link]).
+ and_return([])
expect(subject).to receive(:referenced_by).with([])
@@ -174,13 +174,13 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
end
it 'returns the references if a user can reference and see a link' do
- expect(subject).to receive(:nodes_user_can_reference)
- .with(user, [link])
- .and_return([link])
+ expect(subject).to receive(:nodes_user_can_reference).
+ with(user, [link]).
+ and_return([link])
- expect(subject).to receive(:nodes_visible_to_user)
- .with(user, [link])
- .and_return([link])
+ expect(subject).to receive(:nodes_visible_to_user).
+ with(user, [link]).
+ and_return([link])
expect(subject).to receive(:referenced_by).with([link])
@@ -192,8 +192,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
it 'delegates the permissions check to the Ability class' do
user = double(:user)
- expect(Ability).to receive(:allowed?)
- .with(user, :read_project, project)
+ expect(Ability).to receive(:allowed?).
+ with(user, :read_project, project)
subject.can?(user, :read_project, project)
end
@@ -201,8 +201,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
describe '#find_projects_for_hash_keys' do
it 'returns a list of Projects' do
- expect(subject.find_projects_for_hash_keys(project.id => project))
- .to eq([project])
+ expect(subject.find_projects_for_hash_keys(project.id => project)).
+ to eq([project])
end
end
@@ -214,8 +214,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
expect(collection).to receive(:where).twice.and_call_original
2.times do
- expect(subject.collection_objects_for_ids(collection, [user.id]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(collection, [user.id])).
+ to eq([user])
end
end
end
@@ -229,8 +229,8 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
end
it 'queries the collection on the first call' do
- expect(subject.collection_objects_for_ids(User, [user.id]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(User, [user.id])).
+ to eq([user])
end
it 'does not query previously queried objects' do
@@ -239,34 +239,34 @@ describe Banzai::ReferenceParser::BaseParser, lib: true do
expect(collection).to receive(:where).once.and_call_original
2.times do
- expect(subject.collection_objects_for_ids(collection, [user.id]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(collection, [user.id])).
+ to eq([user])
end
end
it 'casts String based IDs to Fixnums before querying objects' do
2.times do
- expect(subject.collection_objects_for_ids(User, [user.id.to_s]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(User, [user.id.to_s])).
+ to eq([user])
end
end
it 'queries any additional objects after the first call' do
other_user = create(:user)
- expect(subject.collection_objects_for_ids(User, [user.id]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(User, [user.id])).
+ to eq([user])
- expect(subject.collection_objects_for_ids(User, [user.id, other_user.id]))
- .to eq([user, other_user])
+ expect(subject.collection_objects_for_ids(User, [user.id, other_user.id])).
+ to eq([user, other_user])
end
it 'caches objects on a per collection class basis' do
- expect(subject.collection_objects_for_ids(User, [user.id]))
- .to eq([user])
+ expect(subject.collection_objects_for_ids(User, [user.id])).
+ to eq([user])
- expect(subject.collection_objects_for_ids(Project, [project.id]))
- .to eq([project])
+ expect(subject.collection_objects_for_ids(Project, [project.id])).
+ to eq([project])
end
end
end
diff --git a/spec/lib/banzai/reference_parser/commit_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_parser_spec.rb
index 9c2b2c0a1a9..412ffa77c36 100644
--- a/spec/lib/banzai/reference_parser/commit_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/commit_parser_spec.rb
@@ -30,30 +30,30 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do
it 'returns an Array of commits' do
commit = double(:commit)
- allow_any_instance_of(Project).to receive(:valid_repo?)
- .and_return(true)
+ allow_any_instance_of(Project).to receive(:valid_repo?).
+ and_return(true)
- expect(subject).to receive(:find_commits)
- .with(project, ['123'])
- .and_return([commit])
+ expect(subject).to receive(:find_commits).
+ with(project, ['123']).
+ and_return([commit])
expect(subject.referenced_by([link])).to eq([commit])
end
it 'returns an empty Array when the commit could not be found' do
- allow_any_instance_of(Project).to receive(:valid_repo?)
- .and_return(true)
+ allow_any_instance_of(Project).to receive(:valid_repo?).
+ and_return(true)
- expect(subject).to receive(:find_commits)
- .with(project, ['123'])
- .and_return([])
+ expect(subject).to receive(:find_commits).
+ with(project, ['123']).
+ and_return([])
expect(subject.referenced_by([link])).to eq([])
end
it 'skips projects without valid repositories' do
- allow_any_instance_of(Project).to receive(:valid_repo?)
- .and_return(false)
+ allow_any_instance_of(Project).to receive(:valid_repo?).
+ and_return(false)
expect(subject.referenced_by([link])).to eq([])
end
@@ -61,8 +61,8 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do
context 'when the link does not have a data-commit attribute' do
it 'returns an empty Array' do
- allow_any_instance_of(Project).to receive(:valid_repo?)
- .and_return(true)
+ allow_any_instance_of(Project).to receive(:valid_repo?).
+ and_return(true)
expect(subject.referenced_by([link])).to eq([])
end
@@ -71,8 +71,8 @@ describe Banzai::ReferenceParser::CommitParser, lib: true do
context 'when the link does not have a data-project attribute' do
it 'returns an empty Array' do
- allow_any_instance_of(Project).to receive(:valid_repo?)
- .and_return(true)
+ allow_any_instance_of(Project).to receive(:valid_repo?).
+ and_return(true)
expect(subject.referenced_by([link])).to eq([])
end
diff --git a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb
index 5aec04e8d5b..96e55b0997a 100644
--- a/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/commit_range_parser_spec.rb
@@ -30,17 +30,17 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do
it 'returns an Array of commit ranges' do
range = double(:range)
- expect(subject).to receive(:find_object)
- .with(project, '123..456')
- .and_return(range)
+ expect(subject).to receive(:find_object).
+ with(project, '123..456').
+ and_return(range)
expect(subject.referenced_by([link])).to eq([range])
end
it 'returns an empty Array when the commit range could not be found' do
- expect(subject).to receive(:find_object)
- .with(project, '123..456')
- .and_return(nil)
+ expect(subject).to receive(:find_object).
+ with(project, '123..456').
+ and_return(nil)
expect(subject.referenced_by([link])).to eq([])
end
@@ -86,17 +86,17 @@ describe Banzai::ReferenceParser::CommitRangeParser, lib: true do
it 'returns an Array of range objects' do
range = double(:commit)
- expect(subject).to receive(:find_object)
- .with(project, '123..456')
- .and_return(range)
+ expect(subject).to receive(:find_object).
+ with(project, '123..456').
+ and_return(range)
expect(subject.find_ranges(project, ['123..456'])).to eq([range])
end
it 'skips ranges that could not be found' do
- expect(subject).to receive(:find_object)
- .with(project, '123..456')
- .and_return(nil)
+ expect(subject).to receive(:find_object).
+ with(project, '123..456').
+ and_return(nil)
expect(subject.find_ranges(project, ['123..456'])).to eq([])
end
diff --git a/spec/lib/banzai/reference_parser/issue_parser_spec.rb b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
index bc81d2808b5..6873b7b85f9 100644
--- a/spec/lib/banzai/reference_parser/issue_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/issue_parser_spec.rb
@@ -18,17 +18,17 @@ describe Banzai::ReferenceParser::IssueParser, lib: true do
it_behaves_like "referenced feature visibility", "issues"
it 'returns the nodes when the user can read the issue' do
- expect(Ability).to receive(:issues_readable_by_user)
- .with([issue], user)
- .and_return([issue])
+ expect(Ability).to receive(:issues_readable_by_user).
+ with([issue], user).
+ and_return([issue])
expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
end
it 'returns an empty Array when the user can not read the issue' do
- expect(Ability).to receive(:issues_readable_by_user)
- .with([issue], user)
- .and_return([])
+ expect(Ability).to receive(:issues_readable_by_user).
+ with([issue], user).
+ and_return([])
expect(subject.nodes_visible_to_user(user, [link])).to eq([])
end
diff --git a/spec/lib/banzai/reference_parser/user_parser_spec.rb b/spec/lib/banzai/reference_parser/user_parser_spec.rb
index f2f11cd5088..31ca9d27b0b 100644
--- a/spec/lib/banzai/reference_parser/user_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/user_parser_spec.rb
@@ -82,17 +82,17 @@ describe Banzai::ReferenceParser::UserParser, lib: true do
end
it 'returns the nodes if the user can read the group' do
- expect(Ability).to receive(:allowed?)
- .with(user, :read_group, group)
- .and_return(true)
+ expect(Ability).to receive(:allowed?).
+ with(user, :read_group, group).
+ and_return(true)
expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
end
it 'returns an empty Array if the user can not read the group' do
- expect(Ability).to receive(:allowed?)
- .with(user, :read_group, group)
- .and_return(false)
+ expect(Ability).to receive(:allowed?).
+ with(user, :read_group, group).
+ and_return(false)
expect(subject.nodes_visible_to_user(user, [link])).to eq([])
end
@@ -115,9 +115,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do
link['data-project'] = other_project.id.to_s
- expect(Ability).to receive(:allowed?)
- .with(user, :read_project, other_project)
- .and_return(true)
+ expect(Ability).to receive(:allowed?).
+ with(user, :read_project, other_project).
+ and_return(true)
expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
end
@@ -127,9 +127,9 @@ describe Banzai::ReferenceParser::UserParser, lib: true do
link['data-project'] = other_project.id.to_s
- expect(Ability).to receive(:allowed?)
- .with(user, :read_project, other_project)
- .and_return(false)
+ expect(Ability).to receive(:allowed?).
+ with(user, :read_project, other_project).
+ and_return(false)
expect(subject.nodes_visible_to_user(user, [link])).to eq([])
end