Sha256: 0a0a7412b97a2986922dda8a8f0cf2447ed9f27e04cd73a6d594dd5481792b86

Contents?: true

Size: 1.46 KB

Versions: 44

Compression:

Stored size: 1.46 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../spec_helper')

describe RailsBestPractices::Checks::MoveModelLogicIntoModelCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveModelLogicIntoModelCheck.new)
  end
  
  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.check('app/controllers/posts_controller.rb', content)
    errors = @runner.errors
    errors.should_not be_empty
    errors[0].to_s.should == "app/controllers/posts_controller.rb:3 - move model logic into model (@post called_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.check('app/controllers/posts_controller.rb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
rails_best_practices-0.4.0 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.27 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.26 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.25 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.24 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.23 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.22 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.21 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.20 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.19 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.18 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.17 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.16 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.15 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.14 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.13 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.12 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.11 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.10 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb
rails_best_practices-0.3.9 spec/rails_best_practices/checks/move_model_logic_into_model_check_spec.rb