Sha256: 5221cbe760df4c89861eea9877c1f1e93909ba3139de0300eb8b1941d70df074

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

require "rails_helper"

describe Curupira::RelationshipSelectOptionsHelper do
  describe "#active_user_groups_select_options" do

    context 'when user is admin' do
      let!(:user){FactoryGirl.create(:user, admin:true)}
      let!(:active_group1) { FactoryGirl.create(:group, active: true) }
      let!(:active_group2) { FactoryGirl.create(:group, active: true) }

      it "return groups" do
        expect(helper.active_user_groups_select_options(user)).to eql [
          ["Selecione um grupo", nil],
          [active_group1.name, active_group1.id],
          [active_group2.name, active_group2.id]
        ]
      end      
    end

    context 'when user is not admin' do
      let!(:active_group1) { FactoryGirl.create(:group, active: true) }
      let!(:active_group2) { FactoryGirl.create(:group, active: true) }
      let!(:inactive_group) { FactoryGirl.create(:group, active: false) }
      let!(:user) { FactoryGirl.create(:user, groups: [active_group1, active_group2]) }

      it "returns default with active groups" do
        expect(helper.active_user_groups_select_options(user)).to eql [
          ["Selecione um grupo", nil],
          [active_group1.name, active_group1.id],
          [active_group2.name, active_group2.id]
        ]
      end
      context "when doesnt belongs to any group" do
        let!(:user2) { FactoryGirl.create(:user)}
        it "doesnt return any groups" do
          expect(helper.active_user_groups_select_options(user2)).to eql [
            ["Selecione um grupo", nil]
          ]
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
curupira-0.1.7 spec/helpers/relationship_select_options_helper_spec.rb
curupira-0.1.6 spec/helpers/relationship_select_options_helper_spec.rb
curupira-0.1.4 spec/helpers/relationship_select_options_helper_spec.rb
curupira-0.1.3 spec/helpers/relationship_select_options_helper_spec.rb
curupira-0.1.2 spec/helpers/relationship_select_options_helper_spec.rb
curupira-0.1.1 spec/helpers/relationship_select_options_helper_spec.rb