<commit_before>#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require 'spec_helper'

describe PhotosController do
  before do
    @alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
    @bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true)

    @controller.stub!(:current_user).and_return(alice)
    sign_in :user, alice
    request.env["HTTP_REFERER"] = ''
  end

  describe '#create' do
    before do
      @controller.stub!(:file_handler).and_return(uploaded_photo)
      @params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} }
    end

    it "creates a photo" do
      lambda {
        post :create, @params
      }.should change(Photo, :count).by(1)
    end

    it 'can set the photo as the profile photo' do
      old_url = alice.person.profile.image_url
      @params[:photo][:set_profile_photo] = true
      post :create, @params
      alice.reload.person.profile.image_url.should_not == old_url
    end
  end

  describe '#index' do
    it "displays the logged in user's pictures" do
      get :index, :person_id => alice.person.id.to_s
      assigns[:person].should == alice.person<commit_msg>Add test for Opera photo upload.<commit_after>#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require 'spec_helper'

describe PhotosController do
  before do
    @alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
    @bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true)

    @controller.stub!(:current_user).and_return(alice)
    sign_in :user, alice
    request.env["HTTP_REFERER"] = ''
  end
  
  describe '#create' do
    before do
      @params = {:photo => {:aspect_ids => "all"}, :qqfile => Rack::Test::UploadedFile.new("spec/fixtures/button.png", "image/png") }
    end
    
    it 'accepts a photo from a regular form submission' do
      lambda {
        post :create, @params
      }.should change(Photo, :count).by(1)
    end
  end

  describe '#create' do
    before do
      @controller.stub!(:file_handler).and_return(uploaded_photo)
      @params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} }
    end

    it "creates a photo" do
      lambda {
        post :create, @params
      }.should change(Photo, :count).by(1)
    end

    it 'can set the photo as the profile photo' do
      old_url = alice.person.profile.image_url
      @params[:photo][:set_profile_photo] = true
      post :create, @params
      alice.reload.person.profile.image_url.should_not == old_url
    end
  end

  describe '#index' do
    it "displays the logged in user's pictures" do
      get :index, :person_id => alice.person.id.to_s
      assigns[:person].should == alice.person
{'fraction_non_alphanumeric': 0.12409479921000659, 'fraction_numerical': 0.0069124423963133645, 'mean_word_length': 3.197513812154696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5096681', 'n_tokens_mistral': 1038, 'n_tokens_neox': 992, 'n_words': 266}