Sha256: 3ee08234ed89c47eb46341cd4d56ce7975cc85baf4539804259c63ded01b074d

Contents?: true

Size: 1.51 KB

Versions: 11

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::Models::Repository do

  let(:adapter)     { nil }
  let(:site)        { nil }
  let(:locale)      { :en }
  let(:repository)  { ArticleRepository.new(adapter, site, locale) }

  describe '#locale' do

    subject { repository.locale }

    it { is_expected.to eq :en }

    context 'change the locale' do

      before { repository.locale = :fr }

      it { is_expected.to eq :fr }

    end

  end

  describe '#scope' do

    subject { repository.scope }

    it { expect(subject.locale).to eq :en }

    context 'change the locale from the repository' do

      before { subject; repository.locale = :fr }

      it { expect(subject.locale).to eq :fr }

    end

  end

  describe '#prepare_conditions' do

    let(:conditions) { [{ 'band_id' => 42, 'order_by' => 'created_at.desc' }] }

    subject { repository.prepare_conditions(*conditions) }

    it { is_expected.to eq({ 'band_id' => 42, 'order_by' => 'created_at.desc' }) }

    context 'with local conditions' do

      let(:local_conditions) { { parent_id: 1, order_by: { position: 'asc' } } }

      before { repository.local_conditions = local_conditions }

      it { is_expected.to eq({ 'parent_id' => 1, 'band_id' => 42, 'order_by' => 'created_at.desc' }) }

      it "doesn't modify the local conditions" do
        subject
        expect(local_conditions).to eq({ parent_id: 1, order_by: { position: 'asc' } })
      end

    end

  end

  class ArticleRepository
    include Locomotive::Steam::Models::Repository
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.8.0.alpha1 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.7.1 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.7.0 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.6.1 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.6.0 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.6.0.rc1 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.6.0.beta1 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.5.3 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.5.2 spec/unit/models/repository_spec.rb
locomotivecms_steam-1.5.1 spec/unit/models/repository_spec.rb