Sha256: b0a080c2290908478e48269a0f2588d0beee78c60fe1f310fa99241cfa553ea2

Contents?: true

Size: 1.36 KB

Versions: 17

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

describe RailsBestPractices::Reviews::MoveModelLogicIntoModelReview do
  let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::MoveModelLogicIntoModelReview.new) }

  it "should move model logic into model" do
    content = <<-EOF
    class PostsController < ApplicationController

      def publish
        @post = Post.find(params[:id])
        @post.update_attributes(:is_published, true)
        @post.approved_by = current_user
        if @post.created_at > Time.now - 7.days
          @post.popular = 100
        else
          @post.popular = 0
        end
      end

      redirect_to post_url(@post)
    end
    EOF
    runner.review('app/controllers/posts_controller.rb', content)
    runner.should have(1).errors
    runner.errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post use_count > 4)"
  end

  it "should not move model logic into model with simple model calling" do
    content = <<-EOF
    class PostsController < ApplicationController

      def publish
        @post = Post.find(params[:id])
        @post.update_attributes(:is_published, true)
        @post.approved_by = current_user
      end

      redirect_to post_url(@post)
    end
    EOF
    runner.review('app/controllers/posts_controller.rb', content)
    runner.should have(0).errors
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
rails_best_practices-1.1.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-1.0.1 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-1.0.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.10.1 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.10.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-raydog153-0.9.1 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.9.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.8.2 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.8.1 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.8.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.5 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.4 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.3 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.2 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.1 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.7.0 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb
rails_best_practices-0.6.7 spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb