Skip to content

Commit

Permalink
letzte specs ergänzt
Browse files Browse the repository at this point in the history
  • Loading branch information
Widu Wittekindt committed Mar 29, 2012
1 parent 7a88342 commit da78347
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 13 deletions.
4 changes: 0 additions & 4 deletions app/controllers/registrations_controller.rb
Expand Up @@ -3,10 +3,6 @@ class RegistrationsController < Devise::RegistrationsController
after_filter :inform_admin, :only => :create
protected

def after_sign_up_path_for(resource)
new_user_session_path
end

def after_inactive_sign_up_path_for(resource)
new_user_session_path
end
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/users_controller.rb
Expand Up @@ -80,12 +80,7 @@ def destroy
end

def change_approved

if params[:approve] && @user.approved
flash[:notice] = 'Ist shon passiert'
redirect_to users_path, :notice => t('controller.users.allready_approved') and return
end

redirect_to users_path, :notice => t('controller.users.allready_approved') and return if params[:approve] && @user.approved
@user.toggle_approved

respond_to do |format|
Expand Down
13 changes: 13 additions & 0 deletions spec/controllers/apllication_controller_spec.rb
Expand Up @@ -8,4 +8,17 @@
self.controller.send(:after_sign_out_path_for, User).should == new_user_session_path
end
end

describe "after_sign_in_path_for" do
after :all do
I18n.locale = :de
end

it "set the default locale for a user" do
@user = FactoryGirl.create(:approved_user)
@user.locale = 'pt'
self.controller.send(:after_sign_in_path_for, @user)
I18n.locale.should == :pt
end
end
end
30 changes: 30 additions & 0 deletions spec/controllers/bookings_controller_spec.rb
Expand Up @@ -225,4 +225,34 @@ def valid_attributes
end
end
end

describe "update_options" do
before :each do
sign_in (@current_user = FactoryGirl.create(:admin_user))
@own_booking = FactoryGirl.create(:booking, :user => @current_user)
@params = {:sample => 'Test'}
end

it "assigns an existing booking to @booking if a booking_id is given" do
get :update_options, :booking => @params.merge({:id => @own_booking.id}), :format => :js
assigns(:booking).should eq(@own_booking)
end

it "updates the attributes of an existing booking" do
get :update_options, :booking => @params.merge({:id => @own_booking.id}), :format => :js
assigns(:booking).sample.should_not == @own_booking.sample
assigns(:booking).sample.should == @params[:sample]
end

it "assigns a new booking to @booking if no booking_id is given" do
get :update_options, :booking => {}, :format => :js
assigns(:booking).should be_new_record
assigns(:booking).should be_a(Booking)
end

it "valildates the booking" do
Booking.any_instance.should_receive(:valid?)
get :update_options, :booking => {}, :format => :js
end
end
end
12 changes: 11 additions & 1 deletion spec/controllers/calendar_controller_spec.rb
Expand Up @@ -15,7 +15,7 @@

context "with user logged in" do
before :each do
sign_in FactoryGirl.create :approved_user
sign_in @user = FactoryGirl.create(:approved_user)
end

describe "GET index" do
Expand Down Expand Up @@ -63,6 +63,16 @@
@calendar.machines.should_not include(@machines[1], @machines[3], @machines[5])
end

it "respects the user set defaults for the machines" do
@machines = FactoryGirl.create_list(:machine, 5)
@user.default_machines = [@machines[1], @machines[3]]
get :index
@calendar = assigns(:calendar)
@calendar.machines.should include(@machines[1], @machines[3])
@calendar.machines.should have(2).machines
@calendar.machines.should_not include(@machines[0], @machines[2], @machines[4])
end

it "respects an offset for machines" do
@machines = FactoryGirl.create_list(:machine, 7)
get :index, :machine_offset => 1
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/registrations_controller_spec.rb
Expand Up @@ -29,5 +29,22 @@
end
end
end

describe "locale set" do
after :all do
I18n.locale = :de
end

it "does set the locale" do
post :create, :locale => 'en'
I18n.locale.should == :en
end

it "does return an error if the requested locale does not exist" do
post :create, :locale => 'pt'
I18n.locale.should == :en
flash[:notice].should == 'pt translation not available'
end
end
end

19 changes: 17 additions & 2 deletions spec/controllers/users_controller_spec.rb
Expand Up @@ -196,17 +196,32 @@ def valid_attributes
end

describe "change approved" do
it "changes the 'approved' value from true to false" do
it "changes the 'approved' value from false to true" do
get :change_approved, :id => @user
@user.reload.should be_approved
end

it "changes the 'approved' value from false to true" do
it "changes the 'approved' value from true to false" do
@user = FactoryGirl.create(:approved_user)
get :change_approved, :id => @user
@user.reload.should_not be_approved
end

context "with approve only param" do
it "changes the 'approved' value from false to true" do
get :change_approved, :id => @user, :approve => true
@user.reload.should be_approved
end

it "does not change the 'approved' value from true to false" do
@user = FactoryGirl.create(:approved_user)
get :change_approved, :id => @user, :approve => true
@user.reload.should be_approved
flash[:notice].should == I18n.t('controller.users.allready_approved')
end
end


context "of current user" do
it "does not change the account" do
expect{
Expand Down

0 comments on commit da78347

Please sign in to comment.