Commit ae226fa402a69691d1b859ac82b06ad882627dfb
1 parent
5e639f7b
Exists in
master
and in
29 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,7 +160,7 @@ class Profile < ActiveRecord::Base | ||
160 | validates_presence_of :identifier, :name | 160 | validates_presence_of :identifier, :name |
161 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT | 161 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT |
162 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS | 162 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS |
163 | - validates_uniqueness_of :identifier | 163 | + validates_uniqueness_of :identifier, :scope => :environment_id |
164 | 164 | ||
165 | validates_length_of :nickname, :maximum => 16, :allow_nil => true | 165 | validates_length_of :nickname, :maximum => 16, :allow_nil => true |
166 | 166 |
lib/needs_profile.rb
@@ -21,7 +21,7 @@ module NeedsProfile | @@ -21,7 +21,7 @@ module NeedsProfile | ||
21 | end | 21 | end |
22 | 22 | ||
23 | def load_profile | 23 | def load_profile |
24 | - @profile ||= Profile.find_by_identifier(params[:profile]) | 24 | + @profile ||= environment.profiles.find_by_identifier(params[:profile]) |
25 | render_not_found unless @profile | 25 | render_not_found unless @profile |
26 | end | 26 | end |
27 | 27 |
test/functional/content_viewer_controller_test.rb
@@ -31,7 +31,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -31,7 +31,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
31 | page = profile.articles.build(:name => 'test') | 31 | page = profile.articles.build(:name => 'test') |
32 | page.save! | 32 | page.save! |
33 | 33 | ||
34 | - uses_host 'anhetegua.net' | 34 | + uses_host 'colivre.net' |
35 | get :view_page, :profile => profile.identifier, :page => [ 'test' ] | 35 | get :view_page, :profile => profile.identifier, :page => [ 'test' ] |
36 | assert_response :success | 36 | assert_response :success |
37 | assert_equal page, assigns(:page) | 37 | assert_equal page, assigns(:page) |
@@ -517,4 +517,15 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -517,4 +517,15 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
517 | assert_response :missing | 517 | assert_response :missing |
518 | end | 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 | end | 531 | end |
test/functional/memberships_controller_test.rb
@@ -222,10 +222,13 @@ class MembershipsControllerTest < Test::Unit::TestCase | @@ -222,10 +222,13 @@ class MembershipsControllerTest < Test::Unit::TestCase | ||
222 | template.boxes << Box.new | 222 | template.boxes << Box.new |
223 | template.boxes[0].blocks << Block.new | 223 | template.boxes[0].blocks << Block.new |
224 | template.save! | 224 | template.save! |
225 | + | ||
225 | env = Environment.create!(:name => 'test_env') | 226 | env = Environment.create!(:name => 'test_env') |
226 | env.settings[:community_template_id] = template.id | 227 | env.settings[:community_template_id] = template.id |
227 | env.save! | 228 | env.save! |
228 | 229 | ||
230 | + profile.environment = env | ||
231 | + profile.save! | ||
229 | @controller.stubs(:environment).returns(env) | 232 | @controller.stubs(:environment).returns(env) |
230 | 233 | ||
231 | post :new_community, :profile => profile.identifier, :community => { :name => 'test community', :description => 'a test community'} | 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,6 +946,27 @@ class ProfileTest < Test::Unit::TestCase | ||
946 | end | 946 | end |
947 | end | 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 | private | 970 | private |
950 | 971 | ||
951 | def assert_invalid_identifier(id) | 972 | def assert_invalid_identifier(id) |