|
| 1 | +require 'rails/all' |
| 2 | +require_relative '../test_helper' |
| 3 | +require_relative 'abstract_controller' |
| 4 | +require_relative 'user' |
| 5 | +require_relative 'project' |
| 6 | + |
| 7 | +describe Sync::Partial do |
| 8 | + include TestHelper |
| 9 | + |
| 10 | + before do |
| 11 | + @user = User.new |
| 12 | + @project = Project.new |
| 13 | + end |
| 14 | + |
| 15 | + describe '#name' do |
| 16 | + it 'returns the underscored model class name' do |
| 17 | + assert_equal "user", Sync::Resource.new(@user).name |
| 18 | + end |
| 19 | + end |
| 20 | + |
| 21 | + describe '#plural_name' do |
| 22 | + it 'returns the underscored model class name' do |
| 23 | + assert_equal "users", Sync::Resource.new(@user).plural_name |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe '#id' do |
| 28 | + it 'returns the models id' do |
| 29 | + assert_equal 1, Sync::Resource.new(@user).id |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe '#channel' do |
| 34 | + it 'returns nil when no channel is given' do |
| 35 | + refute Sync::Resource.new(@user).channel |
| 36 | + end |
| 37 | + |
| 38 | + it 'sets the channel to the passed string' do |
| 39 | + assert_equal "admin", Sync::Resource.new(@user, "admin").channel |
| 40 | + end |
| 41 | + |
| 42 | + it 'sets the channel as the joined array of symbols' do |
| 43 | + assert_equal "admin/restricted", Sync::Resource.new(@user, [:admin, :restricted]).channel |
| 44 | + end |
| 45 | + |
| 46 | + it 'sets the channel as the joined array of strings' do |
| 47 | + assert_equal "admin/restricted", Sync::Resource.new(@user, ["admin", "restricted"]).channel |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + describe 'parent' do |
| 52 | + it 'defaults to NullResource if no parent is given' do |
| 53 | + assert_equal Sync::NullResource, Sync::Resource.new(@user).parent.class |
| 54 | + end |
| 55 | + |
| 56 | + it 'sets the parent to given resource' do |
| 57 | + resource = Sync::Resource.new(@user) |
| 58 | + parent = Sync::Resource.new(@user) |
| 59 | + resource.parent = parent |
| 60 | + assert_equal parent, resource.parent |
| 61 | + end |
| 62 | + end |
| 63 | + |
| 64 | + describe '#polymorphic_path' do |
| 65 | + it 'returns the path for the model' do |
| 66 | + assert_equal "/users/1", Sync::Resource.new(@user).polymorphic_path.to_s |
| 67 | + end |
| 68 | + |
| 69 | + it 'returns the path for the model, prefixed by parent path' do |
| 70 | + child = Sync::Resource.new(@user) |
| 71 | + child.parent = Sync::Resource.new(@project) |
| 72 | + assert_equal "/projects/1/users/1", child.polymorphic_path.to_s |
| 73 | + end |
| 74 | + |
| 75 | + it 'returns the path for the model, prefixed by parent path and channel' do |
| 76 | + child = Sync::Resource.new(@user) |
| 77 | + child.parent = Sync::Resource.new(@project, :admin) |
| 78 | + assert_equal "/admin/projects/1/users/1", child.polymorphic_path.to_s |
| 79 | + end |
| 80 | + end |
| 81 | + |
| 82 | + describe '#polymorphic_new_path' do |
| 83 | + it 'returns the path for the model' do |
| 84 | + assert_equal "/users/new", Sync::Resource.new(@user).polymorphic_new_path.to_s |
| 85 | + end |
| 86 | + |
| 87 | + it 'returns the path for the model, prefixed by parent path' do |
| 88 | + child = Sync::Resource.new(@user) |
| 89 | + child.parent = Sync::Resource.new(@project) |
| 90 | + assert_equal "/projects/1/users/new", child.polymorphic_new_path.to_s |
| 91 | + end |
| 92 | + |
| 93 | + it 'returns the path for the model, prefixed by parent path and channel' do |
| 94 | + child = Sync::Resource.new(@user) |
| 95 | + child.parent = Sync::Resource.new(@project, :admin) |
| 96 | + assert_equal "/admin/projects/1/users/new", child.polymorphic_new_path.to_s |
| 97 | + end |
| 98 | + end |
| 99 | +end |
0 commit comments