daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require File.dirname(__FILE__) + '/../spec_helper'
  2.  
  3. describe Picture, 'associations' do
  4.   it 'should belong to merchant' do
  5.     Picture.new.should belong_to(:merchant)
  6.   end
  7. end
  8.  
  9. describe 'Maximum picture file size limit' do
  10.   it 'should be given in megabytes' do
  11.     Picture.max_upload_file_size_limit.should == (Picture::IMAGE_FILE_SIZE_RANGE.end / 1.megabyte)
  12.   end  
  13. end
  14.  
  15. describe 'Valid image types list' do
  16.   it 'should say gif, jpg or png' do
  17.     Picture.valid_image_types_sentence.should == '.gif, .jpg or .png'
  18.   end
  19. end
  20.  
  21. describe Picture, 'protected attributes' do
  22.   it 'should protect merchant id' do
  23.     (@pic = Picture.new(:merchant_id => 0)).merchant_id.should_not == 0
  24.   end
  25. end
  26.  
  27. describe Picture, 'validations' do
  28.   include PictureSpecHelper
  29.   it 'should not prohibit upload of text files' do
  30.     # No expensive I/O operation just to get file size!
  31.     File.should_receive(:size).with(anything).and_return(0.25.megabytes)
  32.    
  33.     image = uploaded_file('text_file.txt')
  34.     image.valid?
  35.     image.errors.full_messages.should include('Image has unsupported format.')
  36.   end
  37.  
  38.   it 'should prohibit upload of files greater than 2 megabytes' do
  39.     # No expensive I/O operation just to get file size!
  40.     File.should_receive(:size).with(anything).and_return(2.7.megabytes)    
  41.     image = uploaded_file('mail_in_leopard.png')
  42.     image.valid?
  43.     image.errors.full_messages.should include('Image is larger than the allowed size range.')
  44.   end
  45. end
  46.  
  47. describe Picture, 'new uploaded picture' do
  48.   before :each do
  49.     @new_pic = Picture.new
  50.   end
  51.  
  52.   it 'should not be used as logo' do
  53.     @new_pic.should_not be_logo
  54.   end
  55.  
  56.   it 'should not be hidden' do
  57.     @new_pic.should_not be_hidden
  58.   end
  59.  
  60.   it 'should be unreviewed' do
  61.     @new_pic.should_not be_reviewed
  62.   end
  63.  
  64.   it 'should be appropriate' do
  65.     @new_pic.should be_appropriate
  66.   end
  67.  
  68.   it 'should not be marked innapropriate by user' do
  69.     @new_pic.should_not be_user_inappropriate
  70.   end
  71. end
  72.  
  73.  
  74. describe Picture, 'logo assignment' do
  75.   fixtures :pictures
  76.  
  77.   before :each do
  78.     @logo = pictures(:as_logo)
  79.     @pic  = pictures(:one)    
  80.   end
  81.  
  82.   def use_picture_as_logo(picture)
  83.     picture.use_as_logo!
  84.   end
  85.  
  86.   it 'should have logo and non_logo(test prerequisite)' do
  87.     @logo.should be_logo
  88.     @pic.should_not be_logo
  89.   end
  90.  
  91.   it 'should set logo attribute' do
  92.     use_picture_as_logo(@pic)
  93.     @pic.should be_logo
  94.   end
  95.  
  96.   it 'should clear logo attribute(requires model reload)' do    
  97.     use_picture_as_logo(@pic)
  98.     @logo.reload.should_not be_logo
  99.   end
  100. end
  101.  
  102. describe Picture, 'after hide' do
  103.   fixtures :pictures
  104.  
  105.   it 'should be hidden' do    
  106.     (@pic = pictures(:not_hidden)).should_not be_hidden
  107.     @pic.hide!
  108.     @pic.should be_hidden
  109.   end
  110. end
  111.  
  112. describe Picture, 'after reveal' do
  113.   fixtures :pictures
  114.   it 'after unhide!' do
  115.     (@pic = pictures(:hidden)).should be_hidden
  116.     @pic.unhide!
  117.     @pic.should_not be_hidden
  118.   end
  119. end
  120.  
  121. describe Picture, 'when marked inappropriate' do
  122.   fixtures :pictures
  123.  
  124.   it 'should be reviewed' do
  125.     (@pic = pictures(:unreviewed)).should_not be_reviewed
  126.     @pic.inappropriate!
  127.     @pic.should be_reviewed
  128.   end
  129.  
  130. end
  131.  
  132. describe Picture, 'when marked appropriate' do
  133.   fixtures :pictures
  134.   it 'should be reviewed' do
  135.     (@pic = pictures(:unreviewed)).should_not be_reviewed
  136.     @pic.appropriate!
  137.     @pic.should be_reviewed
  138.   end
  139. end
  140.  
  141.  
  142. describe Picture, 'when marked as innapropriate by user' do
  143.   fixtures :pictures
  144.   it 'should not be reviewed' do
  145.     (@pic = pictures(:unreviewed)).should_not be_reviewed
  146.     @pic.user_inappropriate!
  147.     @pic.should_not be_reviewed
  148.   end
  149. end
  150.  
  151. describe "Pictures without review finder" do
  152.   fixtures :pictures
  153.  
  154.   it 'should find unreviewed picture' do
  155.     Picture.with_unreviewed_scope {
  156.       Picture.find :all
  157.     }.should include(pictures(:unreviewed))
  158.   end
  159.  
  160.   it 'should NOT find reviewed pictures' do
  161.     Picture.with_unreviewed_scope {
  162.       Picture.find :all
  163.     }.should_not include(pictures(:reviewed))
  164.   end
  165. end
  166.  
  167. describe Picture, 'after being marked as appropriate' do
  168.   fixtures :pictures
  169.  
  170.   it 'should be appropriate' do
  171.     (@pic = pictures(:inappropriate)).should_not be_appropriate
  172.     @pic.appropriate!
  173.  
  174.     @pic.should be_appropriate
  175.   end
  176. end
  177.  
  178. describe Picture, 'after being marked as inappropriate' do
  179.   fixtures :pictures
  180.  
  181.   it 'should be inappropriate' do
  182.     (@pic = pictures(:appropriate)).should be_appropriate
  183.     @pic.inappropriate!
  184.     @pic.should_not be_appropriate
  185.   end
  186.  
  187.   it 'should NOT be marked inappropriate by user' do    
  188.     (@pic = pictures(:user_inappropriate)).should be_user_inappropriate
  189.     @pic.inappropriate!
  190.     @pic.should_not be_user_inappropriate
  191.   end
  192. end
  193.  
  194. describe 'Appropriate pictures finder' do
  195.   fixtures :pictures
  196.  
  197.   it 'should find appropriate' do
  198.     Picture.with_appropriate_scope {
  199.       Picture.find :all
  200.     }.should include(pictures(:appropriate))
  201.   end
  202.  
  203.   it 'should NOT find inappropriate' do
  204.     Picture.with_appropriate_scope {
  205.       Picture.find :all
  206.     }.should_not include(pictures(:inappropriate))
  207.   end  
  208. end
  209.  
  210. describe 'Inappropriate pictures finder' do
  211.   fixtures :pictures
  212.  
  213.   it 'should find inappropriate' do
  214.     Picture.with_inappropriate_scope {
  215.       Picture.find :all
  216.     }.should include(pictures(:inappropriate))
  217.   end
  218.  
  219.   it 'should NOT find appropriate' do
  220.     Picture.with_inappropriate_scope {
  221.       Picture.find :all
  222.     }.should_not include(pictures(:appropriate))
  223.   end
  224. end
  225.  
  226. describe Picture, 'after being marked as appropriated' do
  227.   fixtures :pictures
  228.  
  229.   before :each do
  230.     @inappropriate      = pictures(:inappropriate)
  231.     @user_inappropriate = pictures(:user_inappropriate)
  232.    
  233.     Picture.appropriate([@inappropriate, @user_inappropriate])
  234.   end
  235.  
  236.   it 'should not be found by inappropriate finder' do
  237.     Picture.with_inappropriate_scope do
  238.       Picture.find :all
  239.     end.should_not include(@inappropriate)    
  240.   end
  241.  
  242.   it 'should not be found by user inappropriate finder' do
  243.     Picture.with_user_inappropriate_scope do
  244.       Picture.find :all
  245.     end.should_not include(@user_inappropriate)
  246.   end
  247.  
  248.   it 'should update review time' do
  249.     @inappropriate.reviewed_at.should be_nil
  250.     @inappropriate.reload # required
  251.     @inappropriate.reviewed_at.should be_kind_of(Time)
  252.   end
  253. end
  254.  
  255.  
  256. describe Picture, 'being marked as inappropriate by user' do
  257.   fixtures :pictures
  258.  
  259.   it 'should become user_inappropriate' do
  260.     (@pic = pictures(:one)).should_not be_user_inappropriate
  261.     @pic.user_inappropriate!
  262.     @pic.should be_user_inappropriate
  263.   end
  264. end
  265.  
  266. describe Picture, 'being marked as appropriate by user' do
  267.   fixtures :pictures
  268.  
  269.   it 'should become user_appropriate' do
  270.     (@pic = pictures(:user_inappropriate)).should be_user_inappropriate
  271.     @pic.user_appropriate!
  272.     @pic.should_not be_user_inappropriate
  273.   end
  274. end
  275.  
  276. describe Picture, 'finding user_inappropriate' do
  277.   fixtures :pictures
  278.  
  279.   it 'should find user_inappropriate' do
  280.     Picture.with_user_inappropriate_scope {
  281.       Picture.find :all
  282.     }.should include(pictures(:user_inappropriate))
  283.   end
  284.  
  285.   it 'should not include user_appropriate in found' do
  286.     Picture.with_user_inappropriate_scope {
  287.       Picture.find :all
  288.     }.should_not include(pictures(:user_appropriate))
  289.   end
  290. end
  291.  
  292. describe 'Hidden images finder' do
  293.   fixtures :pictures
  294.  
  295.   before :each do
  296.     @hidden = Picture.with_hidden_scope(true) { Picture.find(:all) }
  297.   end
  298.  
  299.   it 'should include hidden images' do
  300.     @hidden.should include(pictures(:hidden))
  301.   end
  302.  
  303.   it 'should not include public images' do
  304.     @hidden.should_not include(pictures(:public))
  305.   end
  306. end
  307.  
  308. describe 'Public images finder' do
  309.   fixtures :pictures
  310.  
  311.   before :each do
  312.     @pictures = Picture.with_public_scope { Picture.find(:all) }
  313.   end
  314.  
  315.   it 'should not include hidden pictures' do
  316.     @pictures.should_not include(pictures(:hidden))
  317.   end
  318.  
  319.   it 'should include appropriate' do
  320.     @pictures.should include(pictures(:appropriate))
  321.   end
  322.  
  323.   it 'should not include inappropriate' do
  324.     @pictures.should_not include(pictures(:inappropriate))
  325.   end
  326. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top