require 'spec_helper'

describe "fetprofiles/show", :type => :view  do
  foreach_theme do 

    before(:each) do
      default_url_options[:locale] = :de
      @fetprofile =  FactoryGirl.create(:fetprofile_withadress)
      assign(:fetprofile,@fetprofile)
      @gremium =  FactoryGirl.create(:gremium)
      @gremium2 =  FactoryGirl.create(:gremium, name:"Kommission2")
      @gremium3 =  FactoryGirl.create(:gremium, name:"Kommission3", typ: 2)

      assign(:memberships, [FactoryGirl.create(:membership,gremium_id: @gremium.id, fetprofile_id: @fetprofile.id)])
      assign(:gremientabs, [@gremium2])
      #    view.theme "blue2"
    end

    it "has working filters" do 
      expect(true).to be true
    end
    it "calls vorname on fetprofile" do
      expect(@fetprofile).to receive(:vorname).at_least(1).times

      render
    end
    
    it "doesn't call users" do
      Fetprofile.any_instance.should_not_receive(:users)
      #  expect(Fetprofile.any_instance).to receive(:vorname) 
      render
    end

    it "doesn't call memberships" do
      Fetprofile.any_instance.should_not_receive(:memberships)
      render
    end

    it "doesn't call gremien" do
      Fetprofile.any_instance.should_not_receive(:gremien)
      render
    end
    
    it "renders public attributes" do
      render
      expect(rendered).to match(/#{@fetprofile.vorname}/)
      expect(rendered).to match(/#{@fetprofile.nachname}/)
      expect(rendered).to match(/#{@fetprofile.desc}/)
      expect(rendered).to match(/#{@fetprofile.fetmail}/)
      
      expect(rendered).to have_tag('div')
      
      #    rendered.should match(/Nachname/)
      #    rendered.should match(/Short/)
      #    rendered.should match(/Fetmailalias/)
      #    rendered.should match(/MyText/)

      #    rendered.should match(/false/)
    end
    it "doesn't render address" do
      render 
      expect(rendered).not_to match(/#{@fetprofile.street}/)
      expect(rendered).not_to match(/#{@fetprofile.city}/)
      expect(rendered).not_to match(/#{@fetprofile.hdynr}/)
      expect(rendered).not_to match(/#{@fetprofile.telnr}/)
      expect(rendered).not_to match(/#{@fetprofile.plz}/)

    end
    it  "renders links to gremium" do
      render
      expect(rendered).to match(/#{gremium_path(@gremium)}/)
    end
    it  "renders  gremium links"  do
      render
      expect(rendered).to match(/#{gremium_path(@gremium2)}/)
    end
    it  "doesn't render  gremium links for hidden gremium"  do
      render
      expect(rendered).not_to match(/#{gremium_path(@gremium3)}/)
    end

    describe "with fet user" do 
      login_fet_user

      #    let(:current_ability) {@ability}
      it "renders address" do 
        render
        expect(rendered).to match(/#{@fetprofile.street}/)
        expect(rendered).to match(/#{@fetprofile.plz}/)
        expect(rendered).to match(/#{@fetprofile.city}/)
        expect(rendered).to match(/#{@fetprofile.hdynr}/)
        expect(rendered).to match(/#{@fetprofile.telnr}/)

      end
      it  "renders edit path" do
        render
        expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/)
      end
    end
  end
end
