OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
linting spec file
ulfertsda00b6bac8d0
diff --git a/spec/lib/api/v3/queries/query_representer_rendering_spec.rb b/spec/lib/api/v3/queries/query_representer_rendering_spec.rbindex 30576c4bc91..094573072e6 100644--- a/spec/lib/api/v3/queries/query_representer_rendering_spec.rb+++ b/spec/lib/api/v3/queries/query_representer_rendering_spec.rb@@ -28,13 +28,13 @@require 'spec_helper'-describe ::API::V3::Queries::QueryRepresenter do+describe ::API::V3::Queries::QueryRepresenter doinclude ::API::V3::Utilities::PathHelperlet(:query) { FactoryBot.build_stubbed(:query, project: project) }let(:unpersisted_query) { FactoryBot.build(:query, project: project, user: other_user) }let(:project) { FactoryBot.build_stubbed(:project) }- let(:user) { double('current_user', allowed_to_globally?: true, allowed_to?: true, admin: true, admin?: true, active?: true) }+ let(:user) { instance_double('User', allowed_to_globally?: true, allowed_to?: true, admin: true, admin?: true, active?: true) }let(:other_user) { FactoryBot.build_stubbed(:user) }let(:embed_links) { true }let(:representer) do@@ -44,7 +44,7 @@ describe ::API::V3::Queries::QueryRepresenter dolet(:permissions) { [] }let(:policy) do- policy_stub = double('policy stub')+ policy_stub = instance_double(QueryPolicy)allow(QueryPolicy).to receive(:new)@@ -80,7 +80,7 @@ describe ::API::V3::Queries::QueryRepresenter dosubject { representer.to_json }describe '_links' do- context 'self' do+ describe 'self' doit_behaves_like 'has a titled link' dolet(:link) { 'self' }let(:href) { api_v3_paths.query(query.id) }@@ -132,7 +132,7 @@ describe ::API::V3::Queries::QueryRepresenter dolet(:href) { api_v3_paths.query_project_schema(project.identifier) }end- context 'has no project' do+ context 'when the query has no project' dolet(:query) { FactoryBot.build_stubbed(:query, project: nil) }it_behaves_like 'has an empty link' do@@ -328,7 +328,7 @@ describe ::API::V3::Queries::QueryRepresenter doquery = FactoryBot.build_stubbed(:query, project: project)query.add_filter('subject', '~', ['bogus'])query.group_by = 'author'- query.sort_criteria = [['assigned_to', 'asc'], ['type', 'desc']]+ query.sort_criteria = [%w[assigned_to asc], %w[type desc]]queryend@@ -341,7 +341,7 @@ describe ::API::V3::Queries::QueryRepresenter doshowSums: false,showHierarchies: false,groupBy: 'author',- sortBy: JSON::dump([['assignee', 'asc'], ['type', 'desc']])+ sortBy: JSON::dump([%w[assignee asc], %w[type desc]])}api_v3_paths.work_packages_by_project(project.id) + "?#{params.to_query}"@@ -390,7 +390,7 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has an empty columns array' do- is_expected+ expect(subject).to be_json_eql([].to_json).at_path('_links/columns')end@@ -400,7 +400,7 @@ describe ::API::V3::Queries::QueryRepresenter dolet(:query) doquery = FactoryBot.build_stubbed(:query, project: project)- query.column_names = ['status', 'assigned_to', 'updated_at']+ query.column_names = %w[status assigned_to updated_at]queryend@@ -421,7 +421,7 @@ describe ::API::V3::Queries::QueryRepresenter doexpected = [status, assignee, subproject]- is_expected+ expect(subject).to be_json_eql(expected.to_json).at_path('_links/columns')end@@ -453,7 +453,7 @@ describe ::API::V3::Queries::QueryRepresenter docontext 'without sort_by' doit 'has an empty sortBy array' do- is_expected+ expect(subject).to be_json_eql([].to_json).at_path('_links/sortBy')end@@ -462,7 +462,7 @@ describe ::API::V3::Queries::QueryRepresenter docontext 'with sort_by' dolet(:query) doFactoryBot.build_stubbed(:query,- sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']])+ sort_criteria: [%w[subject asc], %w[assigned_to desc]])endit 'has an array of sortBy' do@@ -477,7 +477,7 @@ describe ::API::V3::Queries::QueryRepresenter do}]- is_expected+ expect(subject).to be_json_eql(expected.to_json).at_path('_links/sortBy')end@@ -485,6 +485,7 @@ describe ::API::V3::Queries::QueryRepresenter docontext 'when not starred' dolet(:permissions) { %i(star unstar) }+before doallow(query).to receive(:starred)@@ -497,22 +498,23 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has no unstar link' do- is_expected- .to_not have_json_path('_links/unstar')+ expect(subject)+ .not_to have_json_path('_links/unstar')end- context 'lacking permission' do+ context 'when lacking permission' dolet(:permissions) { [] }it 'has no star link' do- is_expected- .to_not have_json_path('_links/star')+ expect(subject)+ .not_to have_json_path('_links/star')endendendcontext 'when starred' dolet(:permissions) { %i(star unstar) }+before doallow(query).to receive(:starred)@@ -525,22 +527,22 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has no star link' do- is_expected- .to_not have_json_path('_links/star')+ expect(subject)+ .not_to have_json_path('_links/star')end- context 'lacking permission' do+ context 'when lacking permission' dolet(:permissions) { [] }it 'has no unstar link' do- is_expected- .to_not have_json_path('_links/unstar')+ expect(subject)+ .not_to have_json_path('_links/unstar')endendendend- context 'properties' do+ describe 'properties' doit_behaves_like 'property', :_type dolet(:value) { 'Query' }end@@ -605,71 +607,69 @@ describe ::API::V3::Queries::QueryRepresenter dodescribe 'highlighting' docontext 'with EE', with_ee: %i[conditional_highlighting] do- it 'renders when the value is set' do- query.highlighting_mode = 'status'+ let :status do+ {+ href: '/api/v3/queries/columns/status',+ title: 'Status'+ }+ end- is_expected.to be_json_eql('status'.to_json).at_path('highlightingMode')+ let :type do+ {+ href: '/api/v3/queries/columns/type',+ title: 'Type'+ }end- it 'renders the default' do- query.highlighting_mode = nil- query.highlighted_attributes = nil- is_expected.to be_json_eql('inline'.to_json).at_path('highlightingMode')- is_expected.to_not have_json_path('highlightedAttributes')+ let :priority do+ {+ href: '/api/v3/queries/columns/priority',+ title: 'Priority'+ }end- context "inline attribute highlighting" do- let :status do- {- href: '/api/v3/queries/columns/status',- title: 'Status'- }- end+ let :due_date do+ {+ href: '/api/v3/queries/columns/dueDate',+ title: 'Finish date'+ }+ end- let :type do- {- href: '/api/v3/queries/columns/type',- title: 'Type'- }- end+ let(:query) do+ query = FactoryBot.build_stubbed(:query, project: project)- let :priority do- {- href: '/api/v3/queries/columns/priority',- title: 'Priority'- }- end+ query.highlighted_attributes = %w[status type priority due_date]- let :due_date do- {- href: '/api/v3/queries/columns/dueDate',- title: 'Finish date'- }- end+ query+ end- let(:query) do- query = FactoryBot.build_stubbed(:query, project: project)+ let(:highlighted_attributes) do+ [status, priority, due_date]+ end- query.highlighted_attributes = ['status', 'type', 'priority', 'due_date']+ it 'renders when the value is set' do+ query.highlighting_mode = 'status'- query- end+ expect(subject).to be_json_eql('status'.to_json).at_path('highlightingMode')+ end- let(:highlighted_attributes) do- [status, priority, due_date]- end+ it 'renders the default' do+ query.highlighting_mode = nil+ query.highlighted_attributes = nil+ expect(subject).to be_json_eql('inline'.to_json).at_path('highlightingMode')+ expect(subject).not_to have_json_path('highlightedAttributes')+ end- it 'links an array of highlighted attributes' do- is_expected- .to be_json_eql(highlighted_attributes.to_json).at_path('_links/highlightedAttributes')- end+ it 'links an array of highlighted attributes' do+ expect(subject)+ .to be_json_eql(highlighted_attributes.to_json).at_path('_links/highlightedAttributes')+ end- it 'embeds selected inline attributes' do- query.highlighted_attributes[0..0].each_with_index do |attr, index|- is_expected- .to be_json_eql("/api/v3/queries/columns/#{attr}".to_json)- .at_path("_embedded/highlightedAttributes/#{index}/_links/self/href")- end+ it 'embeds selected inline attributes' do+ query.highlighted_attributes[0..0].each_with_index do |attr, index|+ expect(subject)+ .to be_json_eql("/api/v3/queries/columns/#{attr}".to_json)+ .at_path("_embedded/highlightedAttributes/#{index}/_links/self/href")endendend@@ -678,28 +678,28 @@ describe ::API::V3::Queries::QueryRepresenter doit 'renders when the value is set' doquery.highlighting_mode = 'status'- is_expected.to be_json_eql('none'.to_json).at_path('highlightingMode')+ expect(subject).to be_json_eql('none'.to_json).at_path('highlightingMode')endit 'renders none when not set' doquery.highlighting_mode = nil- is_expected.to be_json_eql('none'.to_json).at_path('highlightingMode')+ expect(subject).to be_json_eql('none'.to_json).at_path('highlightingMode')endendend- context 'showHierarchies' do+ describe 'showHierarchies' doit 'is true if query.show_hierarchies is true' doquery.show_hierarchies = true- is_expected.to be_json_eql(true.to_json).at_path('showHierarchies')+ expect(subject).to be_json_eql(true.to_json).at_path('showHierarchies')endit 'is false if query.show_hierarchies is false' doquery.show_hierarchies = false- is_expected.to be_json_eql(false.to_json).at_path('showHierarchies')+ expect(subject).to be_json_eql(false.to_json).at_path('showHierarchies')endend@@ -719,73 +719,76 @@ describe ::API::V3::Queries::QueryRepresenter dolet(:filter_status) { FactoryBot.build_stubbed(:status) }let(:filter_user) { FactoryBot.build_stubbed(:user) }-- it 'should render the filters' do- expected_status = {- "_type": "StatusQueryFilter",- "name": "Status",- "_links": {- "filter": {- "href": "/api/v3/queries/filters/status",- "title": "Status"+ let(:expected_status) do+ {+ _type: "StatusQueryFilter",+ name: "Status",+ _links: {+ filter: {+ href: "/api/v3/queries/filters/status",+ title: "Status"},- "operator": {- "href": api_v3_paths.query_operator(CGI.escape('=')),- "title": "is"+ operator: {+ href: api_v3_paths.query_operator(CGI.escape('=')),+ title: "is"},- "values": [+ values: [{- "href": api_v3_paths.status(filter_status.id),- "title": filter_status.name+ href: api_v3_paths.status(filter_status.id),+ title: filter_status.name}],- "schema": {- "href": api_v3_paths.query_filter_instance_schema('status')+ schema: {+ href: api_v3_paths.query_filter_instance_schema('status')}}}- expected_assignee = {- "_type": "AssigneeQueryFilter",- "name": "Assignee",- "_links": {- "filter": {- "href": "/api/v3/queries/filters/assignee",- "title": "Assignee"+ end+ let(:expected_assignee) do+ {+ _type: "AssigneeQueryFilter",+ name: "Assignee",+ _links: {+ filter: {+ href: "/api/v3/queries/filters/assignee",+ title: "Assignee"},- "operator": {- "href": api_v3_paths.query_operator(CGI.escape('!')),- "title": "is not"+ operator: {+ href: api_v3_paths.query_operator(CGI.escape('!')),+ title: "is not"},- "values": [+ values: [{- "href": api_v3_paths.user(filter_user.id),- "title": filter_user.name+ href: api_v3_paths.user(filter_user.id),+ title: filter_user.name}],- "schema": {- "href": api_v3_paths.query_filter_instance_schema('assignee')+ schema: {+ href: api_v3_paths.query_filter_instance_schema('assignee')}}}+ end+ it 'renders the filters' doexpected = [expected_status, expected_assignee]- is_expected.to be_json_eql(expected.to_json).at_path('filters')+ expect(subject).to be_json_eql(expected.to_json).at_path('filters')endenddescribe 'with sort criteria' dolet(:query) doFactoryBot.build_stubbed(:query,- sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']])+ sort_criteria: [%w[subject asc], %w[assigned_to desc]])endit 'has the sort criteria embedded' do- is_expected+ expect(subject).to be_json_eql('/api/v3/queries/sort_bys/subject-asc'.to_json).at_path('_embedded/sortBy/0/_links/self/href')- is_expected+ expect(subject).to be_json_eql('/api/v3/queries/sort_bys/assignee-desc'.to_json).at_path('_embedded/sortBy/1/_links/self/href')end@@ -795,13 +798,13 @@ describe ::API::V3::Queries::QueryRepresenter dolet(:query) doquery = FactoryBot.build_stubbed(:query, project: project)- query.column_names = ['status', 'assigned_to', 'updated_at']+ query.column_names = %w[status assigned_to updated_at]queryendit 'has the columns embedded' do- is_expected+ expect(subject).to be_json_eql('/api/v3/queries/columns/status'.to_json).at_path('_embedded/columns/0/_links/self/href')end@@ -812,7 +815,7 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has no columns embedded' do- is_expected+ expect(subject).not_to have_json_path('_embedded/columns')endend@@ -828,7 +831,7 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has the group by embedded' do- is_expected+ expect(subject).to be_json_eql('/api/v3/queries/group_bys/status'.to_json).at_path('_embedded/groupBy/_links/self/href')end@@ -839,7 +842,7 @@ describe ::API::V3::Queries::QueryRepresenter doendit 'has no group bys embedded' do- is_expected+ expect(subject).not_to have_json_path('_embedded/groupBy')endend@@ -851,8 +854,9 @@ describe ::API::V3::Queries::QueryRepresenter doquery.timeline_visible = trueendend+it do- is_expected.to be_json_eql('true').at_path('timelineVisible')+ expect(subject).to be_json_eql('true').at_path('timelineVisible')endend@@ -867,7 +871,7 @@ describe ::API::V3::Queries::QueryRepresenter doendit do- is_expected.to be_json_eql(expected.to_json).at_path('timelineLabels')+ expect(subject).to be_json_eql(expected.to_json).at_path('timelineLabels')endend@@ -877,8 +881,9 @@ describe ::API::V3::Queries::QueryRepresenter doquery.timeline_zoom_level = :weeksendend+it do- is_expected.to be_json_eql('weeks'.to_json).at_path('timelineZoomLevel')+ expect(subject).to be_json_eql('weeks'.to_json).at_path('timelineZoomLevel')endendend@@ -891,25 +896,25 @@ describe ::API::V3::Queries::QueryRepresenter doresults: results_representer)end- context 'results are provided' do+ context 'when results are provided' dolet(:results_representer) do{_type: 'BogusResultType'}end- it 'should embed the results' do- is_expected+ it 'embeds the results' do+ expect(subject).to be_json_eql('BogusResultType'.to_json).at_path('_embedded/results/_type')endend- context 'no results provided' do+ context 'when no results are provided' dolet(:results_representer) { nil }- it 'should not embed the results' do- is_expected+ it 'does not embed the results' do+ expect(subject).not_to have_json_path('_embedded/results')endend