From 3d19a4f23eea92a19c8bba3c1340f66991792b0e Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 24 Jul 2012 13:19:22 +0400 Subject: [PATCH] [refs #576] Optimize tests, views and model --- app/models/flash_notify.rb | 2 +- app/views/flash_notifies/edit.html.haml | 2 +- app/views/flash_notifies/index.html.haml | 4 ++-- .../flash_notifies_controller_spec.rb | 18 +++++------------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/models/flash_notify.rb b/app/models/flash_notify.rb index 884e13096..5cc407173 100644 --- a/app/models/flash_notify.rb +++ b/app/models/flash_notify.rb @@ -19,6 +19,6 @@ class FlashNotify < ActiveRecord::Base end def should_show?(cookie_id, cookie_hash_id) - cookie_id.to_i == id && cookie_hash_id == hash_id ? false : true + !(cookie_id.to_i == id && cookie_hash_id == hash_id) end end diff --git a/app/views/flash_notifies/edit.html.haml b/app/views/flash_notifies/edit.html.haml index 2dc979eaa..e545e4c6a 100644 --- a/app/views/flash_notifies/edit.html.haml +++ b/app/views/flash_notifies/edit.html.haml @@ -1,4 +1,4 @@ %h3= t("layout.flash_notifies.edit_header") -= form_for @flash_notify, :url => flash_notifies_path(@flash_notify), :html => { :class => :form } do |f| += form_for @flash_notify, :url => flash_notify_path(@flash_notify), :html => { :class => :form } do |f| = render "form", :f => f diff --git a/app/views/flash_notifies/index.html.haml b/app/views/flash_notifies/index.html.haml index 4b42da4a5..566938029 100644 --- a/app/views/flash_notifies/index.html.haml +++ b/app/views/flash_notifies/index.html.haml @@ -10,8 +10,8 @@ %tbody - @flash_notifies.each do |flash_notify| %tr{:class => cycle("odd", "even")} - %td= flash_notify.body_en.slice(0..15) + "..." - %td= flash_notify.body_ru.slice(0..15) + "..." + %td= flash_notify.body_en.truncate 18 + %td= flash_notify.body_ru.truncate 18 %td= flash_notify.published %td = link_to t("layout.flash_notifies.edit"), edit_flash_notify_path(flash_notify) diff --git a/spec/controllers/flash_notifies_controller_spec.rb b/spec/controllers/flash_notifies_controller_spec.rb index b00301fbd..169bbe8b5 100644 --- a/spec/controllers/flash_notifies_controller_spec.rb +++ b/spec/controllers/flash_notifies_controller_spec.rb @@ -54,24 +54,16 @@ describe FlashNotifiesController do set_session_for(@admin) end - it 'should be able to perform index action' do - get :index - response.should render_template(:index) - end - it 'should load 2 flash notifies objects on index' do get :index assigns[:flash_notifies].count.should == 2 end - it 'should be able to perform new action' do - get :new - response.should render_template(:new) - end - - it 'should be able to perform edit action' do - get :edit - response.should render_template(:edit) + [:index, :new, :edit].each do |action| + it "should be able to perform #{action} action" do + get action, :id => @flash_notify + response.should render_template(action) + end end it 'should be able to perform create action' do