expertiza/expertiza

View on GitHub
spec/controllers/questionnaires_controller_spec.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Block has too many lines. [401/25]
Open

describe QuestionnairesController do
  let(:questionnaire) do
    build(id: 1, name: 'questionnaire', ta_id: 8, course_id: 1, private: false, min_question_score: 0, max_question_score: 5, type: 'ReviewQuestionnaire')
  end
  let(:questionnaire) { build(:questionnaire) }

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

File questionnaires_controller_spec.rb has 403 lines of code (exceeds 250 allowed). Consider refactoring.
Open

describe QuestionnairesController do
  let(:questionnaire) do
    build(id: 1, name: 'questionnaire', ta_id: 8, course_id: 1, private: false, min_question_score: 0, max_question_score: 5, type: 'ReviewQuestionnaire')
  end
  let(:questionnaire) { build(:questionnaire) }
Severity: Minor
Found in spec/controllers/questionnaires_controller_spec.rb - About 5 hrs to fix

    Block has too many lines. [72/25]
    Open

      describe '#update' do
        before(:each) do
          @questionnaire1 = double('Questionnaire', id: 1)
          allow(Questionnaire).to receive(:find).with('1').and_return(@questionnaire1)
          @request_params = { id: 1,

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [61/25]
    Open

      describe '#action_allowed?' do
        let(:questionnaire) { build(:questionnaire, id: 1) }
        let(:instructor) { build(:instructor, id: 1) }
        let(:ta) { build(:teaching_assistant, id: 10, parent_id: 66) }
    
    

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [49/25]
    Open

      describe '#delete' do
        context 'when @questionnaire.assignments returns non-empty array' do
          it 'sends the error message to flash[:error]' do
            questionnaire1 = double('Questionnaire',
                                    name: 'test questionnaire',

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [48/25]
    Open

      describe '#add_new_questions' do
        let(:criterion) { Criterion.new(id: 2, weight: 1, max_label: '', min_label: '', size: '', alternatives: '') }
        let(:dropdown) { Dropdown.new(id: 3, size: '', alternatives: '') }
    
        context 'when adding ScoredQuestion' do

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [46/25]
    Open

        context 'when request_params action is edit or update' do
          before(:each) do
            controller.params = { id: '1', action: 'edit' }
            controller.request.session[:user] = instructor
          end

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [28/25]
    Open

      describe '#new' do
        context 'when request_params[:model] has whitespace in it' do
          it 'creates new questionnaire object and renders questionnaires#new page' do
            request_params = { model: 'Assignment SurveyQuestionnaire' }
            get :new, params: request_params

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [26/25]
    Open

        before(:each) do
          @questionnaire1 = double('Questionnaire', id: 1)
          allow(Questionnaire).to receive(:find).with('1').and_return(@questionnaire1)
          @request_params = { id: 1,
                              questionnaire: { name: 'test questionnaire',

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [26/25]
    Open

      describe '#save_all_questions' do
        context 'when request_params[:save] is not nil, params: request_params[:view_advice] is nil' do
          it 'redirects to questionnaires#edit page after saving all questions' do
            allow(Question).to receive(:find).with('1').and_return(question)
            allow(question).to receive(:save).and_return(true)

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        context 'when @questionnaire is not nil' do
          it 'renders the questionnaires#edit page' do
            allow(Questionnaire).to receive(:find).with('1').and_return(double('Questionnaire', instructor_id: 6))
            user_session = { user: instructor }
            request_params = { id: 1 }
    Severity: Minor
    Found in spec/controllers/questionnaires_controller_spec.rb and 1 other location - About 45 mins to fix
    spec/controllers/courses_controller_spec.rb on lines 30..36

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 40.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Useless assignment to variable - instructor1. Did you mean instructor2?
    Open

              instructor1 = create(:instructor, name: 'test_instructor1')

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    There are no issues that match your filters.

    Category
    Status