<commit_before>require 'spec_helper'

describe MediaMagick do
  describe ApplicationHelper do
    describe 'attachmentUploader' do
      let(:album) { Album.new }

      before do
        album.stub(id: '12345678')
      end

      def conteiner_html(model, relation, type, data_attributes, &block)
        id = "#{model}-#{relation.to_s}-#{type.to_s}"
        classes  = "attachmentUploader"

        content_tag(:div, nil, id: id, class: classes, data: data_attributes) do
          class_eval(&block) if block_given?
        end
      end

      context 'without block' do
        before do
          # album.stub(id: '12345678')

          helper.stub(:render)
        end

        it 'should render /uploader partial' do
          helper.should_receive(:render).with('/uploader')

          helper.attachment_uploader(album, :photos, :image)
        end

        it 'should create a div with data attributes' do
          data_attributes = { id: 12345678, model: 'Album', relation: 'photos', partial: '/uploader' }
          html = conteiner_html('Album', 'photos', 'image', data_attributes)

          helper.attachment_uploader(album, :photos, :image).should eq(html)
        end

        context 'using partials' do
          it 'should create a div with data-partial attributes' do
            html = conteiner_html('Album', 'photos', 'image', { id: 12345678, model: 'Album', relation: 'photos', partial: 'albums/photo'})

            helper.attachment_uploader(album, :photos, :image, partial: 'albums/photo').should eq(html)
          end

          it 'should include partial option on data attributes' do
            helper.should_receive(:render).with('albums/photo')

            helper.attachment_uploader(album, :photos, :image, partial: 'albums/photo')
          end
        end

        # context 'partial for images' do
        #   xit 'should create a div with data-partial attributes' do
        #     helper.attachment_container(album, :photos, as: 'file').should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/file'}))
        #   end

        #   xit 'should include partial option on data attributes' do
        #     helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: {}, partial: '/file')

        #     helper.attachment_container(album, :photos, as: 'file')
        #   end
        # end

        context 'embbeded models' do
          let(:track) { album.tracks.new }

          before do
            track.stub(id: '87654321')
          end

          xit 'should create a div with data-embedded-in-id and data-embedded-in-model attributes' do
            html = conteiner_html('Track', 'files', { id: 87654321, model: 'Track', embedded_in_id: 12345678, embedded_in_model: 'Album', relation: 'files', partial: '/image'})

            helper.attachment_uploader(track, :files, :file, embedded_in: album).should eq(html)
          end

          xit 'should render /upload partial' do
            helper.should_receive(:render).with('/upload', model: track, relations: :files, newAttachments: {}, loadedAttachments: {}, partial: '/image')<commit_msg>fix one more spec<commit_after>require 'spec_helper'

describe MediaMagick do
  describe ApplicationHelper do
    describe 'attachmentUploader' do
      let(:album) { Album.new }

      before do
        album.stub(id: '12345678')
      end

      def conteiner_html(model, relation, type, data_attributes, &block)
        id = "#{model}-#{relation.to_s}-#{type.to_s}"
        classes  = "attachmentUploader"

        content_tag(:div, nil, id: id, class: classes, data: data_attributes) do
          class_eval(&block) if block_given?
        end
      end

      context 'without block' do
        before do
          # album.stub(id: '12345678')

          helper.stub(:render)
        end

        it 'should render /uploader partial' do
          helper.should_receive(:render).with('/uploader')

          helper.attachment_uploader(album, :photos, :image)
        end

        it 'should create a div with data attributes' do
          data_attributes = { id: 12345678, model: 'Album', relation: 'photos', partial: '/uploader' }
          html = conteiner_html('Album', 'photos', 'image', data_attributes)

          helper.attachment_uploader(album, :photos, :image).should eq(html)
        end

        context 'using partials' do
          it 'should create a div with data-partial attributes' do
            html = conteiner_html('Album', 'photos', 'image', { id: 12345678, model: 'Album', relation: 'photos', partial: 'albums/photo'})

            helper.attachment_uploader(album, :photos, :image, partial: 'albums/photo').should eq(html)
          end

          it 'should include partial option on data attributes' do
            helper.should_receive(:render).with('albums/photo')

            helper.attachment_uploader(album, :photos, :image, partial: 'albums/photo')
          end
        end

        # context 'partial for images' do
        #   xit 'should create a div with data-partial attributes' do
        #     helper.attachment_container(album, :photos, as: 'file').should eq(conteiner_html('album', 'photos', { id: 12345678, model: 'Album', relation: 'photos', partial: '/file'}))
        #   end

        #   xit 'should include partial option on data attributes' do
        #     helper.should_receive(:render).with('/upload', model: album, relations: :photos, newAttachments: {}, loadedAttachments: {}, partial: '/file')

        #     helper.attachment_container(album, :photos, as: 'file')
        #   end
        # end

        context 'embbeded models' do
          let(:track) { album.tracks.new }

          before do
            track.stub(id: '87654321')
          end

          it 'should create a div with data-embedded-in-id and data-embedded-in-model attributes' do
            html = conteiner_html('Track', 'files', 'file', { id: 87654321, model: 'Track', embedded_in_id: 12345678, embedded_in_model: 'Album', relation: 'files', partial: '/uploader'})

            helper.attachment_uploader(track, :files, :file, embedded_in: album).should eq(html)
          end

          xit 'should render /upload partial' do
            helper.should_receive(:render).with('/upload', model: track, relations: :files, newAttachments: {}, loadedAttachments: {}, partial: '/uploader')
{'fraction_non_alphanumeric': 0.12225510045164305, 'fraction_numerical': 0.019934589627783834, 'mean_word_length': 2.65093803297328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2008577', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1786, 'n_words': 507}