diff --git a/app/models/environment.rb b/app/models/environment.rb index 6827d07..21bc58f 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -145,6 +145,18 @@ class Environment < ActiveRecord::Base end validates_inclusion_of :redirection_after_login, :in => Environment.login_redirection_options.keys, :allow_nil => true + def self.signup_redirection_options + { + 'keep_on_same_page' => _('Stays on the same page the user was before signup.'), + 'site_homepage' => _('Redirects the user to the environment homepage.'), + 'user_profile_page' => _('Redirects the user to his profile page.'), + 'user_homepage' => _('Redirects the user to his homepage.'), + 'user_control_panel' => _('Redirects the user to his control panel.') + } + end + validates_inclusion_of :redirection_after_signup, :in => Environment.signup_redirection_options.keys, :allow_nil => true + + # ################################################# # Relationships and applied behaviour # ################################################# diff --git a/db/migrate/20140205191914_add_redirection_after_signup_to_environment.rb b/db/migrate/20140205191914_add_redirection_after_signup_to_environment.rb new file mode 100644 index 0000000..d0e2677 --- /dev/null +++ b/db/migrate/20140205191914_add_redirection_after_signup_to_environment.rb @@ -0,0 +1,9 @@ +class AddRedirectionAfterSignupToEnvironment < ActiveRecord::Migration + def self.up + add_column :environments, :redirection_after_signup, :string, :default => 'keep_on_same_page' + end + + def self.down + remove_column :environments, :redirection_after_signup + end +end diff --git a/db/schema.rb b/db/schema.rb index 593c594..faa0350 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,4 @@ -# This file is auto-generated from the current state of the database. Instead of editing this file, +# This file is auto-generated from the current state of the database. Instead of editing this file, # please use the migrations feature of Active Record to incrementally modify your database, and # then regenerate this schema definition. # @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140108132730) do +ActiveRecord::Schema.define(:version => 20140205191914) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -282,6 +282,7 @@ ActiveRecord::Schema.define(:version => 20140108132730) do t.text "signup_welcome_text" t.string "languages" t.string "default_language" + t.string "redirection_after_signup", :default => "keep_on_same_page" end create_table "external_feeds", :force => true do |t| diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index cd901cc..d93cbb7 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -1220,6 +1220,27 @@ class EnvironmentTest < ActiveSupport::TestCase end end + should 'return a Hash on signup redirection options' do + assert_kind_of Hash, Environment.signup_redirection_options + end + + should 'respond to redirection after signup' do + assert_respond_to Environment.new, :redirection_after_signup + end + + should 'allow only environment signup redirection options' do + environment = fast_create(Environment) + environment.redirection_after_signup = 'invalid_option' + environment.save + assert environment.errors.invalid?(:redirection_after_signup) + + Environment.signup_redirection_options.keys.each do |redirection| + environment.redirection_after_signup = redirection + environment.save + assert !environment.errors.invalid?(:redirection_after_signup) + end + end + should 'respond to signup_welcome_text' do assert_respond_to Environment.new, :signup_welcome_text end -- libgit2 0.21.2