diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1fcbb8b..088c0ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,8 @@ RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller config.extend ControllerMacros, :type => :controller config.include Devise::TestHelpers, :type => :view -config.include RSpecHtmlMatchers, :type => :view + config.include RSpecHtmlMatchers, :type => :view + config.extend ViewMacros, :type => :view end @@ -42,7 +43,8 @@ RSpec.configure do |config| # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false - + config.add_setting :themes + config.themes =[:blue2, :blue1] # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. diff --git a/spec/support/view_macros.rb b/spec/support/view_macros.rb new file mode 100644 index 0000000..0f6989e --- /dev/null +++ b/spec/support/view_macros.rb @@ -0,0 +1,30 @@ +module ViewMacros + + def foreach_theme + RSpec.configuration.themes.each do |theme| + context " with theme #{theme}" do + before(:each) do + view.view_paths=[ "app/views/themes/#{theme}", "app/views"] + end + + yield + end + end + end + def login_fet_user + before(:each) do + @request.env["devise.mapping"] = Devise.mappings[:user] + user = FactoryGirl.build(:user) + user = User.find_by_email(user.email) || user + user.save + user.add_role(:fetuser) + # user.confirm! + @user=user + @ability= Ability.new(@user) + # controller.stub(:current_ability) { @ability } + allow(view).to receive(:current_ability).and_return(@ability) + sign_in user + end + end + +end diff --git a/spec/views/fetprofiles/edit.html.erb_spec.rb b/spec/views/fetprofiles/edit.html.erb_spec.rb index c68d7e3..8efc992 100644 --- a/spec/views/fetprofiles/edit.html.erb_spec.rb +++ b/spec/views/fetprofiles/edit.html.erb_spec.rb @@ -1,30 +1,35 @@ require 'spec_helper' -describe "fetprofiles/edit" do - before(:each) do - @fetprofile = assign(:fetprofile, stub_model(Fetprofile, - :vorname => "MyString", - :nachname => "MyString", - :short => "MyString", - :fetmailalias => "MyString", - :desc => "MyText", - :picture => "MyString", - :active => false - )) +describe "fetprofiles/edit", :type=> :view do + foreach_theme do + login_fet_user + before(:each) do + @fetprofile = FactoryGirl.create(:fetprofile_withadress,:skype => "myskypename") + @memberships = [] end it "renders the edit fetprofile form" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form[action=?][method=?]", fetprofile_path(@fetprofile), "post" do - assert_select "input#fetprofile_vorname[name=?]", "fetprofile[vorname]" - assert_select "input#fetprofile_nachname[name=?]", "fetprofile[nachname]" - assert_select "input#fetprofile_short[name=?]", "fetprofile[short]" - assert_select "input#fetprofile_fetmailalias[name=?]", "fetprofile[fetmailalias]" - assert_select "textarea#fetprofile_desc[name=?]", "fetprofile[desc]" - assert_select "input#fetprofile_picture[name=?]", "fetprofile[picture]" - assert_select "input#fetprofile_active[name=?]", "fetprofile[active]" + expect(rendered).to have_tag('form', with: {method:"post"}) do + with_tag "input", with: {name: "fetprofile[vorname]", value: @fetprofile.vorname} + with_tag "input", with: {name: "fetprofile[nachname]", value: @fetprofile.nachname} + with_tag "input", with: {name: "fetprofile[short]", value: @fetprofile.short} + with_tag "textarea", with: {name: "fetprofile[desc]"} + with_tag "input", with: {name: "fetprofile[picture]"} + with_tag "input", with: {name: "fetprofile[picture_cache]"} + + with_tag "input", with: {name: "fetprofile[street]", value: @fetprofile.street} + with_tag "input", with: {name: "fetprofile[plz]", value: @fetprofile.plz} + with_tag "input", with: {name: "fetprofile[city]", value: @fetprofile.city} + with_tag "input", with: {name: "fetprofile[hdynr]", value: @fetprofile.hdynr} + with_tag "input", with: {name: "fetprofile[telnr]", value: @fetprofile.telnr} + with_tag "input", with: {name: "fetprofile[skype]", value: @fetprofile.skype.to_s} + with_tag "input", with: {name: "fetprofile[birth_day]", value: @fetprofile.birth_day} + with_tag "input", with: {name: "fetprofile[birth_month]", value: @fetprofile.birth_month} + end end end +end diff --git a/spec/views/fetprofiles/index.html.erb_spec.rb b/spec/views/fetprofiles/index.html.erb_spec.rb index acfffba..c0ca1ad 100644 --- a/spec/views/fetprofiles/index.html.erb_spec.rb +++ b/spec/views/fetprofiles/index.html.erb_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "fetprofiles/index" , :type=>:view do - +foreach_theme do before(:each) do # default_url_options[:locale] = :de @fetprofile1 = FactoryGirl.create(:fetprofile) @@ -29,3 +29,4 @@ describe "fetprofiles/index" , :type=>:view do end end +end diff --git a/spec/views/fetprofiles/new.html.erb_spec.rb b/spec/views/fetprofiles/new.html.erb_spec.rb index 8b6ce6c..5202ff4 100644 --- a/spec/views/fetprofiles/new.html.erb_spec.rb +++ b/spec/views/fetprofiles/new.html.erb_spec.rb @@ -1,30 +1,35 @@ require 'spec_helper' -describe "fetprofiles/new" do +describe "fetprofiles/new", :type=> :view do + foreach_theme do before(:each) do - assign(:fetprofile, stub_model(Fetprofile, - :vorname => "MyString", - :nachname => "MyString", - :short => "MyString", - :fetmailalias => "MyString", - :desc => "MyText", - :picture => "MyString", - :active => false - ).as_new_record) + @fetprofile = FactoryGirl.create(:fetprofile_withadress,:skype => "myskypename") + @memberships = [] end - it "renders new fetprofile form" do + it "renders the edit fetprofile form" do render # Run the generator again with the --webrat flag if you want to use webrat matchers - assert_select "form[action=?][method=?]", fetprofiles_path, "post" do - assert_select "input#fetprofile_vorname[name=?]", "fetprofile[vorname]" - assert_select "input#fetprofile_nachname[name=?]", "fetprofile[nachname]" - assert_select "input#fetprofile_short[name=?]", "fetprofile[short]" - assert_select "input#fetprofile_fetmailalias[name=?]", "fetprofile[fetmailalias]" - assert_select "textarea#fetprofile_desc[name=?]", "fetprofile[desc]" - assert_select "input#fetprofile_picture[name=?]", "fetprofile[picture]" - assert_select "input#fetprofile_active[name=?]", "fetprofile[active]" + expect(rendered).to have_tag('form', with: {method:"post"}) do + with_tag "input", with: {name: "fetprofile[vorname]"} + with_tag "input", with: {name: "fetprofile[nachname]"} + with_tag "input", with: {name: "fetprofile[short]"} + with_tag "textarea", with: {name: "fetprofile[desc]"} + with_tag "input", with: {name: "fetprofile[picture]"} + with_tag "input", with: {name: "fetprofile[picture_cache]"} + + with_tag "input", with: {name: "fetprofile[street]"} + with_tag "input", with: {name: "fetprofile[plz]"} + with_tag "input", with: {name: "fetprofile[city]"} + with_tag "input", with: {name: "fetprofile[hdynr]"} + with_tag "input", with: {name: "fetprofile[telnr]"} + with_tag "input", with: {name: "fetprofile[skype]"} + with_tag "input", with: {name: "fetprofile[birth_day]"} + with_tag "input", with: {name: "fetprofile[birth_month]"} + end end + end end + diff --git a/spec/views/fetprofiles/show.html.erb_spec.rb b/spec/views/fetprofiles/show.html.erb_spec.rb index 080add3..43f183f 100644 --- a/spec/views/fetprofiles/show.html.erb_spec.rb +++ b/spec/views/fetprofiles/show.html.erb_spec.rb @@ -1,122 +1,101 @@ require 'spec_helper' -#ActionView.lookup_context.prefixes = ['app/views/themes/blue2'] -# ActionView.any_instance.stub!(:view_paths).and_return([ 'app/views/themes/blue2']) - -describe "fetprofiles/show", :type => :view do - ["blue2"].each do |theme| - describe "theme #{theme}" do - before(:each) do - view.view_paths=[ "app/views/themes/#{theme}", "app/views"] - end - before(:each) do - default_url_options[:locale] = :de - @fetprofile = FactoryGirl.create(:fetprofile_withadress) - assign(:fetprofile,@fetprofile) +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 - def self.login_fet_user - before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:user] - user = FactoryGirl.build(:user) - user = User.find_by_email(user.email) || user - user.save - user.add_role(:fetuser) - # user.confirm! - @user=user - @ability= Ability.new(@user) - # controller.stub(:current_ability) { @ability } - allow(view).to receive(:current_ability).and_return(@ability) - sign_in user + assign(:memberships, [FactoryGirl.create(:membership,gremium_id: @gremium.id, fetprofile_id: @fetprofile.id)]) + assign(:gremientabs, [@gremium2]) + # view.theme "blue2" end - 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 "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 - 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') + render + end -# rendered.should match(/Nachname/) -# rendered.should match(/Short/) -# rendered.should match(/Fetmailalias/) -# rendered.should match(/MyText/) + it "doesn't call users" do + Fetprofile.any_instance.should_not_receive(:users) + # expect(Fetprofile.any_instance).to receive(:vorname) + render + end -# rendered.should match(/false/) - end - it "doesn't render address" do - render - expect(rendered).not_to match(/#{@fetprofile.street}/) + 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 + it "renders links to gremium" do render - expect(rendered).to match(/#{edit_fetprofile_path(@fetprofile)}/) + 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 -end -end