Sha256: 3084a498aae0acd8d8fb2b4771df8bbe057b38ebd0e17afb4018a09bf992e696

Contents?: true

Size: 1.8 KB

Versions: 15

Compression:

Stored size: 1.8 KB

Contents

require File.join(File.dirname(__FILE__) + '/../../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.check('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)"
  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.check('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)"
  end
  
  it "should move code into model only check for current if conditional statement" do
    content =<<-EOF
    <% if @post.title %>
      <% if @post.user %>
        <% if @post.description %>
        <% end %>
      <% end %>
    <% end %>
    EOF
    @runner.check('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.check('app/views/posts/show.html.erb', content)
    errors = @runner.errors
    errors.should be_empty
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rails_best_practices-0.4.0 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.27 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.26 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.25 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.24 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.23 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.22 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.21 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.20 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.19 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.18 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.17 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.16 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.15 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb
rails_best_practices-0.3.14 spec/rails_best_practices/checks/move_code_into_model_check_spec.rb