forked from bofh/fetsite
additional neuigkeit test
This commit is contained in:
@@ -2,54 +2,126 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe NeuigkeitenController, :type => :controller do
|
RSpec.describe NeuigkeitenController, :type => :controller do
|
||||||
let(:rubrik) {FactoryGirl.create(:rubrik, public:true)}
|
|
||||||
let(:intern_rubrik) {FactoryGirl.create(:rubrik, public:false, name: "InternRubrik")}
|
|
||||||
let(:user) {FactoryGirl.create(:user)}
|
|
||||||
let(:fet_user) do
|
|
||||||
user=FactoryGirl.create(:user)
|
|
||||||
user.add_role(:fetadmin)
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:neuigkeit) {(FactoryGirl.create(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id, datum: 4.hours.ago))}
|
let(:neuigkeit) {(FactoryGirl.create(:neuigkeit, :with_rubrik))}
|
||||||
let(:intern_neuigkeit) {(FactoryGirl.create(:neuigkeit, rubrik_id: intern_rubrik.id, author_id: user.id, datum: 4.hours.ago))}
|
let(:intern_neuigkeit) {(FactoryGirl.create(:neuigkeit,:with_intern_rubrik))}
|
||||||
let(:valid_session) { {current_user: fet_user} }
|
|
||||||
let(:public_session){{}}
|
let(:valid_session) {{}}
|
||||||
|
|
||||||
|
# setting up shared examples
|
||||||
|
let(:object_class) {Neuigkeit}
|
||||||
|
let(:object_variable) {:neuigkeit}
|
||||||
|
let(:assigned_object_variable){neuigkeit}
|
||||||
|
|
||||||
|
#let(:allow_fet_user) {allow(@controller).to receive(:current_user).and_return(fet_user)}
|
||||||
|
|
||||||
|
|
||||||
describe "GET #show" do
|
describe "GET #show" do
|
||||||
it "render show template" do
|
let(:action) { get :show, {id: neuigkeit.id, rubrik_id: neuigkeit.rubrik.id}}
|
||||||
get :show, {id: neuigkeit.id}, public_session
|
|
||||||
expect(response).to have_http_status(200)
|
it_behaves_like "it is success"
|
||||||
expect(response).to render_template(:show)
|
it_behaves_like "it assigns object"
|
||||||
|
|
||||||
|
context "with internal news" do
|
||||||
|
let(:action) { get :show, {id: intern_neuigkeit.id, rubrik_id: intern_neuigkeit.rubrik.id}}
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
|
|
||||||
|
context "with fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it_behaves_like "it is success"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "denys access to unpublished news" do
|
it "denys access to unpublished news" do
|
||||||
neuigkeit.datum=5.hours.from_now
|
neuigkeit=FactoryGirl.create(:neuigkeit, :unpublished)
|
||||||
neuigkeit.save!
|
get :show, {id: neuigkeit.id}, valid_session
|
||||||
get :show, {id: neuigkeit.id}, public_session
|
|
||||||
expect(response).to have_http_status(302)
|
expect(response).to have_http_status(302)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "denys access to intern news" do
|
|
||||||
get :show, {id: intern_neuigkeit.id}, public_session
|
|
||||||
expect(response).to have_http_status(302)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "assignes neuigkeit" do
|
|
||||||
|
|
||||||
get :show, {id: neuigkeit.id }, public_session
|
|
||||||
expect(assigns(:neuigkeit)).to eq(neuigkeit)
|
|
||||||
end
|
|
||||||
describe "GET #show view contents" do
|
|
||||||
|
|
||||||
|
context "with rendered views" do
|
||||||
render_views
|
render_views
|
||||||
it "renders the name of the neuigkeit" do
|
before do
|
||||||
get :show, {id: neuigkeit.id} , public_session
|
neuigkeit.rubrik
|
||||||
|
intern_neuigkeit
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shows the name" do
|
||||||
|
action
|
||||||
expect(response.body).to match neuigkeit.name
|
expect(response.body).to match neuigkeit.name
|
||||||
end
|
end
|
||||||
it "has linkes to external rubrik" do
|
it "has only links to external rubrik" do
|
||||||
|
get :show, {id: neuigkeit.id}, public_session
|
||||||
|
expect(response.body).to match rubrik.name
|
||||||
|
expect(response.body).not_to match intern_rubrik.name
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it "has all links to internal and external rubriken" do
|
||||||
|
action
|
||||||
|
expect(response.body).to match intern_rubrik.name
|
||||||
|
expect(response.body).to match rubrik.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
it "shows datum in response" do
|
||||||
|
action
|
||||||
|
expect(response.body).to match I18n.l(neuigkeit.datum.to_date)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET #edit" do
|
||||||
|
let(:action) { get :edit, {id: neuigkeit.id, rubrik_id: neuigkeit.rubrik.id}}
|
||||||
|
include_examples "it is restricted"
|
||||||
|
it_behaves_like "it assigns object"
|
||||||
|
it_behaves_like "it assigns persisted object"
|
||||||
|
context "with fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it_behaves_like "it is success"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe "GET #new" do
|
||||||
|
let(:action) { get :new, {rubrik_id: neuigkeit.rubrik.id}}
|
||||||
|
include_examples "it assigns new object"
|
||||||
|
include_examples "it is restricted"
|
||||||
|
context "with fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it_behaves_like "it is success"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET add_calentry" do
|
||||||
|
let(:action) { get :add_calentry, {id: neuigkeit.id, rubrik_id: neuigkeit.rubrik.id}}
|
||||||
|
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
|
context "with fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it_behaves_like "it is success"
|
||||||
|
it "renders edit template" do
|
||||||
|
expect(action).to render_template(:edit)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "adds calentry to neuigkeit" do
|
||||||
|
action
|
||||||
|
expect(assigns(:neuigkeit).calentries).not_to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "GET unpublish" do
|
||||||
|
let(:action) {get :unpublish, {id: neuigkeit.id, rubrik_id: neuigkeit.rubrik.id}}
|
||||||
|
it_behaves_like "it is restricted"
|
||||||
|
context "with fet user" do
|
||||||
|
with_fet_user
|
||||||
|
it "redirects to neuigkeit" do
|
||||||
|
expect(action).to redirect_to(rubrik_neuigkeit_url(rubrik,neuigkeit))
|
||||||
|
end
|
||||||
|
it "assignes unpublished neuigkeit" do
|
||||||
|
action
|
||||||
|
expect(assigns(:neuigkeit)).not_to be_published
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ RSpec.describe Meeting, :type => :model do
|
|||||||
let(:calentry){FactoryGirl.build(:calentry, calendar_id: calendar.id, typ: 2)}
|
let(:calentry){FactoryGirl.build(:calentry, calendar_id: calendar.id, typ: 2)}
|
||||||
let(:meetingtyp){FactoryGirl.create(:meetingtyp, rubrik_id: rubrik.id)}
|
let(:meetingtyp){FactoryGirl.create(:meetingtyp, rubrik_id: rubrik.id)}
|
||||||
let(:meeting){FactoryGirl.build(:meeting, meetingtyp_id: meetingtyp.id)}
|
let(:meeting){FactoryGirl.build(:meeting, meetingtyp_id: meetingtyp.id)}
|
||||||
|
let(:object_variable) {meeting}
|
||||||
|
|
||||||
|
it_behaves_like "a valid object"
|
||||||
|
|
||||||
it "should be created" do
|
it "should be created" do
|
||||||
meeting.calentry=calentry
|
meeting.calentry=calentry
|
||||||
@@ -23,10 +26,14 @@ RSpec.describe Meeting, :type => :model do
|
|||||||
meeting.calentry.dauer=7
|
meeting.calentry.dauer=7
|
||||||
expect(meeting).to be_valid
|
expect(meeting).to be_valid
|
||||||
end
|
end
|
||||||
|
context "without calentry" do
|
||||||
|
# let(:meeting){FactoryGirl.build(:meeting, :without_calentry, meetingtyp_id: meetingtyp.id)}
|
||||||
|
|
||||||
it "should be creating a calentry typ 2" do
|
it "should be creating a calentry typ 2" do
|
||||||
meeting.create_calentry
|
meeting.create_calentry
|
||||||
expect(meeting.calentry.typ).to be 2
|
expect(meeting.calentry.typ).to be 2
|
||||||
end
|
end
|
||||||
|
end
|
||||||
it "should be having an alias title for text" do
|
it "should be having an alias title for text" do
|
||||||
expect(meeting.title).to eq(meeting.text)
|
expect(meeting.title).to eq(meeting.text)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,18 +1,35 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Neuigkeit do
|
describe Neuigkeit do
|
||||||
let(:rubrik) {FactoryGirl.create(:rubrik)}
|
|
||||||
let(:user) {FactoryGirl.create(:user)}
|
let(:neuigkeit) {(FactoryGirl.build(:neuigkeit, :with_rubrik))}
|
||||||
let(:calendar) {FactoryGirl.create(:calendar,updated_at: 1.hour.ago)}
|
let(:intern_neuigkeit) {FactoryGirl.build(:neuigkeit, :with_intern_rubrik)}
|
||||||
let(:neuigkeit) {(FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id))}
|
let(:unpublished_neuigkeit){FactoryGirl.build(:neuigkeit, :unpublished,:with_rubrik)}
|
||||||
let(:attachment) {FactoryGirl.build_stubbed(:attachment)}
|
let(:attachment) {FactoryGirl.build_stubbed(:attachment)}
|
||||||
|
|
||||||
let(:calentry) do
|
let(:calentry) {
|
||||||
c = FactoryGirl.build(:calentry, calendar_id: calendar.id, start: 1.hour.ago, ende: 5.minutes.ago)
|
FactoryGirl.build(:calentry, start: 1.hour.ago, ende: 5.minutes.ago)
|
||||||
c.object=neuigkeit
|
}
|
||||||
c.save
|
|
||||||
c
|
let(:object_variable) {neuigkeit}
|
||||||
|
|
||||||
|
it_behaves_like "a valid object"
|
||||||
|
|
||||||
|
it "is published" do expect(neuigkeit).to be_published end
|
||||||
|
it "is public" do expect(neuigkeit).to be_public end
|
||||||
|
it "has no meeting" do expect(neuigkeit).not_to be_is_annoncement end
|
||||||
|
|
||||||
|
# it "failes" do expect(true).to be_falsey end
|
||||||
|
|
||||||
|
it "is published if datum is in the past" do
|
||||||
|
neuigkeit.datum=5.hours.ago
|
||||||
|
expect(neuigkeit).to be_published
|
||||||
end
|
end
|
||||||
|
it "is unpublished if datum is in the future" do
|
||||||
|
neuigkeit.datum=5.hours.from_now
|
||||||
|
expect(neuigkeit).not_to be_published
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
[ :rubrik, :author].each do |attr| # :title,:text to be discussed
|
[ :rubrik, :author].each do |attr| # :title,:text to be discussed
|
||||||
it "should not be valid without #{attr}" do
|
it "should not be valid without #{attr}" do
|
||||||
@@ -21,18 +38,20 @@ describe Neuigkeit do
|
|||||||
expect(neuigkeit.errors[attr]).to have_at_least(1).items
|
expect(neuigkeit.errors[attr]).to have_at_least(1).items
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it "should be created" do
|
|
||||||
expect(neuigkeit).to be_valid
|
|
||||||
expect(neuigkeit.save).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should be valid" do
|
context "with meeting" do
|
||||||
fp = FactoryGirl.build(:neuigkeit, rubrik_id: rubrik.id, author_id: user.id)
|
let(:neuigkeit) {(FactoryGirl.build(:neuigkeit, :with_rubrik, :with_meeting))}
|
||||||
expect(fp).to be_valid
|
let(:object_variable) {neuigkeit}
|
||||||
|
it_behaves_like "a valid object"
|
||||||
|
it "has meeting" do expect(neuigkeit.meeting).to be_truthy end
|
||||||
|
it "is annoncement" do expect(neuigkeit).to be_is_annoncement end
|
||||||
end
|
end
|
||||||
it "responds to attachments" do
|
it "responds to attachments" do
|
||||||
expect(neuigkeit.respond_to?(:attachments)).to be true
|
expect(neuigkeit.respond_to?(:attachments)).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pending "uses titlepic attachments as picture" do # this test seems broken
|
pending "uses titlepic attachments as picture" do # this test seems broken
|
||||||
expect(neuigkeit.respond_to?(:picture_robust)).to be true
|
expect(neuigkeit.respond_to?(:picture_robust)).to be true
|
||||||
attachment.flag_titlepic = true
|
attachment.flag_titlepic = true
|
||||||
@@ -43,10 +62,6 @@ describe Neuigkeit do
|
|||||||
neuigkeit.calentries << calentry
|
neuigkeit.calentries << calentry
|
||||||
expect(neuigkeit).to be_is_event
|
expect(neuigkeit).to be_is_event
|
||||||
|
|
||||||
end
|
|
||||||
it "it is published if datum is in the past" do
|
|
||||||
neuigkeit.datum=5.hours.ago
|
|
||||||
expect(neuigkeit).to be_published
|
|
||||||
end
|
end
|
||||||
it "" do
|
it "" do
|
||||||
end
|
end
|
||||||
|
|||||||
11
spec/models/shared_examples/basic.rb
Normal file
11
spec/models/shared_examples/basic.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
shared_examples "a valid object" do
|
||||||
|
it "is valid" do
|
||||||
|
expect(object_variable).to be_valid
|
||||||
|
end
|
||||||
|
it "can be saved" do
|
||||||
|
expect(object_variable.save).to be_truthy
|
||||||
|
end
|
||||||
|
# it "failes" do
|
||||||
|
# expect(true).to be_falsey
|
||||||
|
# end
|
||||||
|
end
|
||||||
@@ -16,6 +16,8 @@ require 'devise'
|
|||||||
# in spec/support/ and its subdirectories.
|
# in spec/support/ and its subdirectories.
|
||||||
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
||||||
Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].each {|f| require f}
|
Dir[Rails.root.join("spec/models/shared_examples/**/*.rb")].each {|f| require f}
|
||||||
|
Dir[Rails.root.join("spec/models/shared_examples/*.rb")].each {|f| require f}
|
||||||
|
#require 'models/shared_examples/basic.rb'
|
||||||
Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| require f}
|
Dir[Rails.root.join("spec/controllers/shared_examples/**/*.rb")].each {|f| require f}
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|||||||
@@ -1,9 +1,31 @@
|
|||||||
module ControllerMacros
|
module ControllerMacros
|
||||||
# include Devise::TestHelpers, :type=>:controller
|
# include Devise::TestHelpers, :type=>:controller
|
||||||
|
def with_fet_user
|
||||||
|
|
||||||
|
let(:fet_user) {FactoryGirl.create(:other_user, :fetuser)}
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
allow(@controller).to receive(:current_user).and_return(fet_user)
|
||||||
|
allow(@controller).to receive(:current_ability).and_return(Ability.new(fet_user))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def with_fet_admin
|
||||||
|
|
||||||
|
let(:fet_user)do
|
||||||
|
fet_user=FactoryGirl.create(:other_user)
|
||||||
|
fet_user.add_role("fetadmin")
|
||||||
|
fet_user
|
||||||
|
end
|
||||||
|
before(:each) do
|
||||||
|
allow(@controller).to receive(:current_user).and_return(fet_user)
|
||||||
|
allow(@controller).to receive(:current_ability).and_return(Ability.new(fet_user))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def login_fet_user
|
def login_fet_user
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||||
user = FactoryGirl.build(:user)
|
user = FactoryGirl.build(:other_user)
|
||||||
user = User.find_by_email(user.email) || user
|
user = User.find_by_email(user.email) || user
|
||||||
user.save
|
user.save
|
||||||
user.add_role(:fetuser)
|
user.add_role(:fetuser)
|
||||||
@@ -21,6 +43,7 @@ module ControllerMacros
|
|||||||
sign_in user
|
sign_in user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def logout_user
|
def logout_user
|
||||||
before(:each) do
|
before(:each) do
|
||||||
sign_out :user
|
sign_out :user
|
||||||
|
|||||||
Reference in New Issue
Block a user