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