Commit ae226fa402a69691d1b859ac82b06ad882627dfb
1 parent
5e639f7b
Exists in
master
and in
22 other branches
ActionItem795: making profiles available in only its environments
Showing
5 changed files
with
38 additions
and
3 deletions
Show diff stats
app/models/profile.rb
| ... | ... | @@ -160,7 +160,7 @@ class Profile < ActiveRecord::Base |
| 160 | 160 | validates_presence_of :identifier, :name |
| 161 | 161 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT |
| 162 | 162 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS |
| 163 | - validates_uniqueness_of :identifier | |
| 163 | + validates_uniqueness_of :identifier, :scope => :environment_id | |
| 164 | 164 | |
| 165 | 165 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
| 166 | 166 | ... | ... |
lib/needs_profile.rb
test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -31,7 +31,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
| 31 | 31 | page = profile.articles.build(:name => 'test') |
| 32 | 32 | page.save! |
| 33 | 33 | |
| 34 | - uses_host 'anhetegua.net' | |
| 34 | + uses_host 'colivre.net' | |
| 35 | 35 | get :view_page, :profile => profile.identifier, :page => [ 'test' ] |
| 36 | 36 | assert_response :success |
| 37 | 37 | assert_equal page, assigns(:page) |
| ... | ... | @@ -517,4 +517,15 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
| 517 | 517 | assert_response :missing |
| 518 | 518 | end |
| 519 | 519 | |
| 520 | + should 'not show a profile in an environment that is not its home environment' do | |
| 521 | + p = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => Environment.default) | |
| 522 | + | |
| 523 | + current = Environment.create!(:name => 'test environment') | |
| 524 | + current.domains.create!(:name => 'example.com') | |
| 525 | + uses_host 'www.example.com' | |
| 526 | + | |
| 527 | + get :view_page, :profile => 'mytestprofile', :page => [] | |
| 528 | + assert_response :missing | |
| 529 | + end | |
| 530 | + | |
| 520 | 531 | end | ... | ... |
test/functional/memberships_controller_test.rb
| ... | ... | @@ -222,10 +222,13 @@ class MembershipsControllerTest < Test::Unit::TestCase |
| 222 | 222 | template.boxes << Box.new |
| 223 | 223 | template.boxes[0].blocks << Block.new |
| 224 | 224 | template.save! |
| 225 | + | |
| 225 | 226 | env = Environment.create!(:name => 'test_env') |
| 226 | 227 | env.settings[:community_template_id] = template.id |
| 227 | 228 | env.save! |
| 228 | 229 | |
| 230 | + profile.environment = env | |
| 231 | + profile.save! | |
| 229 | 232 | @controller.stubs(:environment).returns(env) |
| 230 | 233 | |
| 231 | 234 | post :new_community, :profile => profile.identifier, :community => { :name => 'test community', :description => 'a test community'} | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -946,6 +946,27 @@ class ProfileTest < Test::Unit::TestCase |
| 946 | 946 | end |
| 947 | 947 | end |
| 948 | 948 | |
| 949 | + should 'not be possible to have different profiles with the same identifier in the same environment' do | |
| 950 | + env = Environment.create!(:name => 'My test environment') | |
| 951 | + | |
| 952 | + p1 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
| 953 | + | |
| 954 | + p2 = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
| 955 | + assert !p2.valid? | |
| 956 | + | |
| 957 | + assert p2.errors.on(:identifier) | |
| 958 | + assert_equal p1.environment, p2.environment | |
| 959 | + end | |
| 960 | + | |
| 961 | + should 'be possible to have different profiles with the same identifier in different environments' do | |
| 962 | + p1 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile') | |
| 963 | + | |
| 964 | + env = Environment.create!(:name => 'My test environment') | |
| 965 | + p2 = Profile.create!(:identifier => 'mytestprofile', :name => 'My test profile', :environment => env) | |
| 966 | + | |
| 967 | + assert_not_equal p1.environment, p2.environment | |
| 968 | + end | |
| 969 | + | |
| 949 | 970 | private |
| 950 | 971 | |
| 951 | 972 | def assert_invalid_identifier(id) | ... | ... |