Sha256: 80a5e9c17b5bae1555fb2b9aa311ca8b5119a9938c417ba250f45ac3ca2e4a4b

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'spec_helper'

describe RailsBestPractices::Checks::MoveCodeIntoModelCheck do
  before(:each) do
    @runner = RailsBestPractices::Core::Runner.new(RailsBestPractices::Checks::MoveCodeIntoModelCheck.new)
  end

  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)
    errors = @runner.errors
    errors.should_not be_empty
    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)
    errors = @runner.errors
    errors.should_not be_empty
    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)
    errors = @runner.errors
    errors.should be_empty
  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)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_best_practices-0.6.6 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.6.5 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb