Skip to content

Commit

Permalink
Merge e1e3653 into 2e3afb5
Browse files Browse the repository at this point in the history
  • Loading branch information
devton committed Mar 25, 2015
2 parents 2e3afb5 + e1e3653 commit 13619f3
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 12 deletions.
6 changes: 2 additions & 4 deletions app/controllers/application_controller.rb
Expand Up @@ -66,13 +66,11 @@ def set_locale
end

def after_sign_in_path_for(resource_or_scope)
return_to = session[:return_to]
session[:return_to] = nil
(return_to || root_path)
(session.delete(:return_to) || root_path)
end

def redirect_user_back_after_login
if request.env['REQUEST_URI'].present? && !request.xhr?
if request.env['REQUEST_URI'].present? && !request.xhr? && session[:return_to].nil?
session[:return_to] = request.env['REQUEST_URI']
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/omniauth_callbacks_controller.rb
Expand Up @@ -12,8 +12,7 @@ def self.add_providers

flash[:notice] = I18n.t("devise.omniauth_callbacks.success", kind: p.name.capitalize)
sign_in @auth.user, event: :authentication
redirect_to(session[:return_to] || root_path)
session[:return_to] = nil
redirect_to after_sign_in_path_for(@auth.user)
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/projects/contributions_controller.rb
Expand Up @@ -36,14 +36,12 @@ def show
end

def new
@contribution = Contribution.new(project: parent, user: current_user)
@contribution.value = 10
@contribution = Contribution.new(project: parent, value: 10)
authorize @contribution

@title = t('projects.contributions.new.title', name: @project.name)
load_rewards

# Select
if params[:reward_id] && (@selected_reward = @project.rewards.find params[:reward_id]) && !@selected_reward.sold_out?
@contribution.reward = @selected_reward
@contribution.value = "%0.0f" % @selected_reward.minimum_value
Expand Down
4 changes: 4 additions & 0 deletions app/policies/contribution_policy.rb
Expand Up @@ -12,6 +12,10 @@ def resolve
end
end

def new?
record.project.online?
end

def create?
done_by_owner_or_admin? && record.project.online?
end
Expand Down
Expand Up @@ -11,7 +11,7 @@
.w-hidden-small.w-hidden-tiny.u-marginbottom-10.fontsize-largest = t('.title')
.fontsize-base.fontweight-semibold.u-marginbottom-10.u-text-center-small-only.text-success-small-only.fontsize-large-small-only.lineheight-tight = t('.choose_reward')
.w-form.back-reward-form
= simple_form_for [parent, @contribution], html: { id: 'contribution_form' } do |form|
= simple_form_for [:fallback_create, parent, @contribution], html: { method: :get, id: 'contribution_form' } do |form|
= render 'devise/shared/alert'
= form.input_field :referal_link, as: :hidden, value: referal_link
= form.input :reward_id, as: :radio_buttons, collection: @rewards, input_html: {class: 'w-radio-input back-reward-radio-button'}, item_wrapper_class: 'w-radio w-clearfix back-reward-radio-reward', label: ''
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -40,6 +40,7 @@
post :sort, on: :member
end
resources :contributions, {controller: 'projects/contributions'} do
get :fallback_create, to: 'projects/contributions#create', on: :collection
put :credits_checkout, on: :member
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/projects/contributions_controller_spec.rb
Expand Up @@ -132,7 +132,7 @@

context "when no user is logged" do
let(:user){ nil }
it{ is_expected.to redirect_to new_user_registration_path }
it{ is_expected.to render_template("projects/contributions/new") }
end

context "when user is logged in but project.online? is false" do
Expand Down
8 changes: 7 additions & 1 deletion spec/policies/contribution_policy_spec.rb
Expand Up @@ -37,7 +37,13 @@
end
end

permissions(:new?){ it_should_behave_like "create permissions" }
permissions(:new?){
['draft', 'deleted', 'rejected', 'successful', 'failed', 'waiting_funds', 'in_analysis'].each do |state|
it "should deny access if project is #{state}" do
contribution.project.update_attributes state: state
end
end
}

permissions(:create?){ it_should_behave_like "create permissions" }

Expand Down

0 comments on commit 13619f3

Please sign in to comment.