From 588391cb2f4a9584723b9c5f9f75ff79f75ed6e3 Mon Sep 17 00:00:00 2001 From: romanrizzi Date: Wed, 11 Sep 2019 11:52:06 -0300 Subject: [PATCH] Fix broken spec and linting errors --- plugin.rb | 10 +++++----- spec/controllers/queries_controller_spec.rb | 15 +++++++-------- spec/guardian_spec.rb | 14 +++++++++----- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/plugin.rb b/plugin.rb index 2a3333c..cbc7897 100644 --- a/plugin.rb +++ b/plugin.rb @@ -694,7 +694,7 @@ SQL check_params! return save_default_query if @id && @id < 0 - @id = @id ||self.class.alloc_id + @id = @id || self.class.alloc_id DataExplorer.pstore_set "q:#{id}", to_hash end @@ -981,10 +981,10 @@ SQL requires_plugin DataExplorer.plugin_name before_action :check_enabled - before_action :set_group, only: [:group_reports_index, :group_reports_show, :group_reports_run] + before_action :set_group, only: [:group_reports_index, :group_reports_show, :group_reports_run] before_action :set_query, only: [:group_reports_show, :group_reports_run] - attr_reader :group, :query + attr_reader :group, :query def check_enabled raise Discourse::NotFound unless SiteSetting.data_explorer_enabled? @@ -1032,7 +1032,7 @@ SQL end def group_reports_index - return raise Discourse::NotFound unless guardian.user_is_a_member_of_group?(group) + return raise Discourse::NotFound unless guardian.user_is_a_member_of_group?(group) respond_to do |format| format.html { render 'groups/show' } @@ -1220,7 +1220,7 @@ SQL end end end - end + end class DataExplorer::QuerySerializer < ActiveModel::Serializer attributes :id, :sql, :name, :description, :param_info, :created_by, :created_at, :username, :group_ids, :last_run_at diff --git a/spec/controllers/queries_controller_spec.rb b/spec/controllers/queries_controller_spec.rb index 80e51f5..abaa346 100644 --- a/spec/controllers/queries_controller_spec.rb +++ b/spec/controllers/queries_controller_spec.rb @@ -256,7 +256,7 @@ describe DataExplorer::QueryController do let(:user) { Fabricate(:user) } let(:group) { Fabricate(:group, users: [user]) } - + before do log_in_user(user) end @@ -280,15 +280,15 @@ describe DataExplorer::QueryController do describe "#group_reports_index" do - it "only returns queries that the group has access to" do - group.add(user) - make_query('SELECT 1 as value', {name: 'A'}, ["#{group.id}"]) + it "only returns queries that the group has access to" do + group.add(user) + make_query('SELECT 1 as value', { name: 'A' }, ["#{group.id}"]) get :group_reports_index, params: { group_name: group.name }, format: :json expect(response.status).to eq(200) expect(response_json['queries'].length).to eq(1) expect(response_json['queries'][0]['name']).to eq('A') - end + end it "returns a 404 when the user should not have access to the query " do user = Fabricate(:user) @@ -310,10 +310,10 @@ describe DataExplorer::QueryController do describe "#group_reports_run" do it "calls run on QueryController" do - query = make_query('SELECT 1 as value', {name: 'B'}, ["#{group.id}"]) + query = make_query('SELECT 1 as value', { name: 'B' }, ["#{group.id}"]) controller.expects(:run).at_least_once - get :group_reports_run, params: { group_name: group.name, id: query.id }, format: :json + get :group_reports_run, params: { group_name: group.name, id: query.id }, format: :json end it "returns a 404 when the user should not have access to the query " do @@ -362,4 +362,3 @@ describe DataExplorer::QueryController do end end end - diff --git a/spec/guardian_spec.rb b/spec/guardian_spec.rb index 7a5ae23..171a7b5 100644 --- a/spec/guardian_spec.rb +++ b/spec/guardian_spec.rb @@ -1,11 +1,15 @@ +# frozen_string_literal: true + require 'rails_helper' describe Guardian do + before { SiteSetting.data_explorer_enabled = true } + def make_query(group_ids = []) q = DataExplorer::Query.new q.id = Fabrication::Sequencer.sequence("query-id", 1) - q.name ="Query number #{q.id}" + q.name = "Query number #{q.id}" q.sql = "SELECT 1" q.group_ids = group_ids q.save @@ -14,7 +18,7 @@ describe Guardian do let(:user) { build(:user) } let(:admin) { build(:admin) } - + describe "#user_is_a_member_of_group?" do let(:group) { Fabricate(:group) } @@ -49,14 +53,14 @@ describe Guardian do it "is false if the query does not contain the group id" do group.add(user) - + expect(Guardian.new(user).user_can_access_query?(group, make_query)).to eq(false) end it "is false if the user is not member of the group" do query = make_query(["#{group.id}"]) - + expect(Guardian.new(user).user_can_access_query?(group, query)).to eq(false) end end -end \ No newline at end of file +end