Sha256: 087c309b116d0e3d8b867c79183bcd1845d8ae39e3074ab7674b2dbeb9f54a18

Contents?: true

Size: 1.7 KB

Versions: 18

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

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

  it "should move code into model" do
    content =<<-EOF
    <% if current_user && (current_user == @post.user || @post.editors.include?(current_user)) %>
      <%= link_to 'Edit this post', edit_post_url(@post) %>
    <% end %>
    EOF
    runner.review('app/views/posts/show.html.erb', content)
    runner.should have(1).errors
    runner.errors[0].to_s.should == "app/views/posts/show.html.erb:1 - move code into model (@post use_count > 2)"
  end

  it "should move code into model with haml" do
    content =<<-EOF
- if current_user && (current_user == @post.user || @post.editors.include?(current_user))
  = link_to 'Edit this post', edit_post_url(@post)
    EOF
    runner.review('app/views/posts/show.html.haml', content)
    runner.should have(1).errors
    runner.errors[0].to_s.should == "app/views/posts/show.html.haml:1 - move code into model (@post use_count > 2)"
  end

  it "should move code into model only review for current if conditional statement" do
    content =<<-EOF
    <% if @post.title %>
      <% if @post.user %>
        <% if @post.description %>
        <% end %>
      <% end %>
    <% end %>
    EOF
    runner.review('app/views/posts/show.html.erb', content)
    runner.should have(0).errors
  end

  it "should not move code into model" do
    content =<<-EOF
    <% if @post.editable_by?(current_user) %>
      <%= link_to 'Edit this post', edit_post_url(@post) %>
    <% end %>
    EOF
    runner.review('app/views/posts/show.html.erb', content)
    runner.should have(0).errors
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

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