Sha256: 5d081566d02ff3ee6f843c147ede7d4c7b8c3cd3534792765fc1f1b0239875ae

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

module RailsBestPractices
  module Reviews
    describe MoveCodeIntoControllerReview do
      let(:runner) { Core::Runner.new(reviews: MoveCodeIntoControllerReview.new) }

      it "should move code into controller for method call" do
        content = <<-EOF
        <% Post.find(:all).each do |post| %>
          <%=h post.title %>
          <%=h post.content %>
        <% end %>
        EOF
        runner.review('app/views/posts/index.html.erb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
      end

      it "should move code into controller for assign" do
        content = <<-EOF
        <% @posts = Post.all %>
        <% @posts.each do |post| %>
          <%=h post.title %>
          <%=h post.content %>
        <% end %>
        EOF
        runner.review('app/views/posts/index.html.erb', content)
        expect(runner.errors.size).to eq(1)
        expect(runner.errors[0].to_s).to eq("app/views/posts/index.html.erb:1 - move code into controller")
      end

      it "should not move code into controller" do
        content = <<-EOF
        <% @posts.each do |post| %>
          <%=h post.title %>
          <%=h post.content %>
        <% end %>
        EOF
        runner.review('app/views/posts/index.html.erb', content)
        expect(runner.errors.size).to eq(0)
      end

      it "should not check ignored files" do
        runner = Core::Runner.new(reviews: MoveCodeIntoControllerReview.new(ignored_files: /app\/views\/post/))
        content = <<-EOF
        <% Post.find(:all).each do |post| %>
          <%=h post.title %>
          <%=h post.content %>
        <% end %>
        EOF
        runner.review('app/views/posts/index.html.erb', content)
        expect(runner.errors.size).to eq(0)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_best_practices-1.19.0 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.18.1 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.18.0 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.17.0 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.16.0 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.7 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.6 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.4 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.3 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.2 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb
rails_best_practices-1.15.1 spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb