puffer 0.0.29 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/Gemfile.lock +56 -52
- data/README.md +51 -43
- data/VERSION +1 -1
- data/app/assets/javascripts/puffer/application.js +3 -1
- data/app/assets/stylesheets/puffer/application.css +2 -0
- data/app/assets/stylesheets/puffer/puffer.css +5 -9
- data/app/components/base_component.rb +0 -1
- data/app/components/boolean/index.html.erb +1 -1
- data/app/components/boolean_component.rb +1 -1
- data/app/components/references_many/index.html.erb +1 -0
- data/app/components/references_many_component.rb +8 -0
- data/app/components/references_one_component.rb +6 -1
- data/app/components/select/filter.html.erb +2 -0
- data/app/components/select/form.html.erb +1 -1
- data/app/components/select_component.rb +13 -2
- data/app/controllers/admin/puffer_users_controller.rb +5 -1
- data/app/controllers/admin/sessions_controller.rb +4 -1
- data/app/controllers/puffer/base.rb +1 -1
- data/app/controllers/puffer/sessions_base.rb +3 -0
- data/app/controllers/puffer/tree_base.rb +4 -4
- data/app/helpers/puffer_helper.rb +16 -15
- data/app/models/puffer/puffer_user.rb +11 -10
- data/app/models/puffer_user.rb +14 -2
- data/app/views/layouts/puffer.html.erb +16 -17
- data/app/views/layouts/puffer_base.html.erb +1 -2
- data/app/views/layouts/puffer_dashboard.html.erb +2 -2
- data/app/views/puffer/base/edit.html.erb +12 -3
- data/app/views/puffer/base/new.html.erb +12 -3
- data/app/views/puffer/dashboard_base/index.html.erb +5 -5
- data/lib/generators/puffer/component/component_generator.rb +0 -1
- data/lib/generators/puffer/controller/controller_generator.rb +1 -1
- data/lib/generators/puffer/controller/templates/controller.rb +8 -0
- data/lib/puffer.rb +77 -13
- data/lib/puffer/component.rb +14 -9
- data/lib/puffer/controller/auth.rb +41 -2
- data/lib/puffer/controller/config.rb +1 -1
- data/lib/puffer/controller/mutate.rb +15 -6
- data/lib/puffer/extensions/core.rb +4 -0
- data/lib/puffer/extensions/directive_processor.rb +36 -0
- data/lib/puffer/extensions/form.rb +1 -1
- data/lib/puffer/extensions/mapper.rb +74 -149
- data/lib/puffer/field.rb +2 -4
- data/lib/puffer/field_set.rb +3 -15
- data/lib/puffer/filters.rb +105 -0
- data/lib/puffer/orm_adapter/active_record.rb +33 -0
- data/lib/puffer/orm_adapter/base.rb +4 -0
- data/lib/puffer/orm_adapter/mongoid.rb +29 -0
- data/lib/puffer/resource.rb +63 -62
- data/lib/puffer/resource/node.rb +71 -0
- data/lib/puffer/resource/routing.rb +4 -4
- data/lib/puffer/resource/tree.rb +36 -0
- data/puffer.gemspec +28 -8
- data/spec/dummy/app/controllers/admin/posts_controller.rb +1 -1
- data/spec/dummy/app/controllers/admin/users_controller.rb +1 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/orms/active_record_orm_primals_controller.rb +36 -0
- data/spec/dummy/app/controllers/orms/mongoid_orm_primals_controller.rb +42 -0
- data/spec/dummy/app/models/active_record_orm.rb +5 -0
- data/spec/dummy/app/models/active_record_orm/primal.rb +2 -0
- data/spec/dummy/app/models/{mongoid_test.rb → mongoid_orm.rb} +1 -1
- data/spec/dummy/app/models/mongoid_orm/primal.rb +46 -0
- data/spec/dummy/config/environments/development.rb +3 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/db/migrate/20110930183902_create_active_record_orm_primals.rb +17 -0
- data/spec/dummy/db/schema.rb +15 -1
- data/spec/fabricators/active_record_orm/primal.rb +13 -0
- data/spec/fabricators/mongoid_orm/primal.rb +12 -0
- data/spec/generators/puffer/component/component_generator_spec.rb +32 -0
- data/spec/generators/puffer/controller/controller_generator_spec.rb +31 -0
- data/spec/helpers/puffer_helper_spec.rb +62 -0
- data/spec/lib/filters_spec.rb +21 -0
- data/spec/lib/orm_adapter/active_record_spec.rb +33 -0
- data/spec/lib/orm_adapter/base_shared.rb +97 -0
- data/spec/lib/orm_adapter/mongoid_spec.rb +46 -0
- data/spec/lib/resource/routing_spec.rb +5 -5
- data/spec/lib/resource/tree_spec.rb +31 -0
- data/spec/lib/resource_spec.rb +36 -37
- data/spec/spec_helper.rb +3 -2
- metadata +71 -43
- data/app/views/puffer/base/_form.html.erb +0 -11
- data/lib/generators/puffer/component/templates/component_spec.rb +0 -19
- data/lib/puffer/resource/scoping.rb +0 -19
- data/spec/dummy/app/controllers/orms/mongoid_tests_controller.rb +0 -19
- data/spec/lib/params_spec.rb +0 -120
@@ -0,0 +1,12 @@
|
|
1
|
+
Fabricator :mongoid_orm_primal, :class_name => 'mongoid_orm/primal' do
|
2
|
+
string_field { Forgery::LoremIpsum.sentence }
|
3
|
+
symbol_filed { Forgery::LoremIpsum.word.to_sym }
|
4
|
+
select_field { sequence(:select_field) {|i| "option #{i}" } }
|
5
|
+
integer_field { sequence :integer_field }
|
6
|
+
float_field { sequence :float_field }
|
7
|
+
decimal_field { sequence :decimal_field }
|
8
|
+
datetime_field { sequence(:datetime_field) {|i| DateTime.now + i.days } }
|
9
|
+
time_field { sequence(:time_field) {|i| DateTime.now + i.hours } }
|
10
|
+
date_field { sequence(:date_field) {|i| DateTime.now + i.days } }
|
11
|
+
boolean_field { rand 2 }
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Generators are not automatically loaded by Rails
|
4
|
+
require 'generators/puffer/component/component_generator'
|
5
|
+
|
6
|
+
describe Puffer::ComponentGenerator do
|
7
|
+
before { run_generator %w(password) }
|
8
|
+
|
9
|
+
describe 'app/components/password_component.rb' do
|
10
|
+
subject { file('app/components/password_component.rb') }
|
11
|
+
it { should exist }
|
12
|
+
it { should contain "class PasswordComponent < Puffer::Component::Base" }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'app/components/password/index.html.erb' do
|
16
|
+
subject { file('app/components/password/index.html.erb') }
|
17
|
+
it { should exist }
|
18
|
+
it { should contain "# I'm index" }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'app/components/password/form.html.erb' do
|
22
|
+
subject { file('app/components/password/form.html.erb') }
|
23
|
+
it { should exist }
|
24
|
+
it { should contain "# I'm form" }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'app/components/password/filter.html.erb' do
|
28
|
+
subject { file('app/components/password/filter.html.erb') }
|
29
|
+
it { should exist }
|
30
|
+
it { should contain "# I'm filter" }
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Generators are not automatically loaded by Rails
|
4
|
+
require 'generators/puffer/controller/controller_generator'
|
5
|
+
|
6
|
+
describe Puffer::ControllerGenerator do
|
7
|
+
describe 'controller namespaced in admin module added by default' do
|
8
|
+
before { run_generator %w(User name:string email:string) }
|
9
|
+
|
10
|
+
describe 'app/controllers/admin/users_controller.rb' do
|
11
|
+
subject { file('app/controllers/admin/users_controller.rb') }
|
12
|
+
it { should exist }
|
13
|
+
it { should contain "class Admin::UsersController < Puffer::Base" }
|
14
|
+
it { should contain "# field :id" }
|
15
|
+
it { should contain "field :email" }
|
16
|
+
it { should contain "field :password" }
|
17
|
+
it { should contain "# field :created_at" }
|
18
|
+
it { should contain "# field :updated_at" }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'controller namespace can be specified in admin module added by default' do
|
23
|
+
before { run_generator %w(Moderator::User name:string email:string) }
|
24
|
+
|
25
|
+
describe 'app/controllers/moderator/users_controller.rb' do
|
26
|
+
subject { file('app/controllers/moderator/users_controller.rb') }
|
27
|
+
it { should exist }
|
28
|
+
it { should contain "class Moderator::UsersController < Puffer::Base" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the PufferHelper. For example:
|
5
|
+
#
|
6
|
+
# describe PufferHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# helper.concat_strings("this","that").should == "this that"
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
describe PufferHelper do
|
14
|
+
|
15
|
+
it "generates scopes navigation" do
|
16
|
+
helper.stub(:puffer_namespace).and_return(:admin)
|
17
|
+
|
18
|
+
navigation = []
|
19
|
+
helper.puffer_scopes_navigation do |*args|
|
20
|
+
navigation.push args
|
21
|
+
end
|
22
|
+
|
23
|
+
navigation.should == [
|
24
|
+
[:admin, "/admin", true],
|
25
|
+
[:orms, "/orms", false]
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "generates groups navigation" do
|
30
|
+
helper.stub(:puffer_namespace).and_return(:admin)
|
31
|
+
helper.stub(:resource).and_return mock(:resource_node => mock, :root => mock(:resource_node => mock(:group => :posting)))
|
32
|
+
|
33
|
+
navigation = []
|
34
|
+
helper.puffer_groups_navigation do |*args|
|
35
|
+
navigation.push args
|
36
|
+
end
|
37
|
+
|
38
|
+
navigation.should == [
|
39
|
+
[:users, "/admin/users", false],
|
40
|
+
[:posting, "/admin/posts", true],
|
41
|
+
[:news, "/admin/news", false]
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "generates resources navigation" do
|
46
|
+
helper.stub(:puffer_namespace).and_return(:admin)
|
47
|
+
helper.stub(:configuration).and_return mock(:group => :posting)
|
48
|
+
helper.stub(:resource).and_return mock(:resource_node => mock, :root => mock(:resource_node => Rails.application.routes.resources_tree[15]))
|
49
|
+
|
50
|
+
navigation = []
|
51
|
+
helper.puffer_resources_navigation do |*args|
|
52
|
+
navigation.push args
|
53
|
+
end
|
54
|
+
|
55
|
+
navigation.should == [
|
56
|
+
["Post", "/admin/posts", false],
|
57
|
+
["Tagged post", "/admin/tagged_posts", false],
|
58
|
+
["Category", "/admin/categories", true]
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Puffer::Filters do
|
4
|
+
|
5
|
+
describe 'controller filters class generation' do
|
6
|
+
|
7
|
+
it 'should generate class with proper name' do
|
8
|
+
Puffer::Filters.controller_filters(Admin::UsersController).should == Admin::UsersControllerFilters
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return Puffer::Filters subclass' do
|
12
|
+
Puffer::Filters.controller_filters(Admin::UsersController).superclass.should == Puffer::Filters
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set proper attributes' do
|
16
|
+
Puffer::Filters.controller_filters(Admin::PostsController).new.attributes.keys.should == %w(user.email status title body puffer_search puffer_order)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lib/orm_adapter/base_shared'
|
3
|
+
|
4
|
+
describe "ActiveRecordOrm" do
|
5
|
+
|
6
|
+
describe 'columns_hash' do
|
7
|
+
it 'should be proper' do
|
8
|
+
ActiveRecordOrm::Primal.to_adapter.columns_hash.should == {
|
9
|
+
"id" => {:type => :integer},
|
10
|
+
"string_field" => {:type => :string},
|
11
|
+
"text_field" => {:type => :text},
|
12
|
+
"select_field" => {:type => :string},
|
13
|
+
"integer_field" => {:type => :integer},
|
14
|
+
"float_field" => {:type => :float},
|
15
|
+
"decimal_field" => {:type => :decimal},
|
16
|
+
"datetime_field" => {:type => :datetime},
|
17
|
+
"timestamp_field" => {:type => :datetime},
|
18
|
+
"time_field" => {:type => :time},
|
19
|
+
"date_field" => {:type => :date},
|
20
|
+
"boolean_field" => {:type => :boolean}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'filter' do
|
26
|
+
it_should_behave_like "an adapter" do
|
27
|
+
let(:model) {ActiveRecordOrm::Primal}
|
28
|
+
let(:fabric) {:active_record_orm_primal}
|
29
|
+
let(:controller) {Orms::ActiveRecordOrmPrimalsController}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples "an adapter" do
|
4
|
+
|
5
|
+
def filter options = {}
|
6
|
+
model.to_adapter.filter(model, controller.index_fields, options).all.to_a
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def nth *indexes
|
11
|
+
model.all.to_a.values_at *indexes
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'without params' do
|
15
|
+
|
16
|
+
before do
|
17
|
+
5.times { Fabricate fabric }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return all records' do
|
21
|
+
filter.should == model.all.to_a
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'search' do
|
27
|
+
|
28
|
+
before do
|
29
|
+
string_fields = %w(hello hello world hello world)
|
30
|
+
select_fields = %w(hello world helloworld hello world)
|
31
|
+
5.times { |i|
|
32
|
+
Fabricate fabric, :string_field => string_fields[i], :select_field => select_fields[i]
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return all searched records' do
|
37
|
+
filter(:search => 'hel').should == nth(0, 1, 2, 3)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return searched records without conditioned' do
|
41
|
+
filter(:search => 'hel', :conditions => {'select_field' => 'hello'}).should == nth(0, 3)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return searched records without conditioned' do
|
45
|
+
filter(:search => 'hel', :conditions => {'select_field' => 'world'}).should == nth(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'select' do
|
51
|
+
|
52
|
+
before do
|
53
|
+
select_fields = %w(hello world hello hello world)
|
54
|
+
boolean_fields = %w(true false false true false)
|
55
|
+
5.times { |i|
|
56
|
+
Fabricate fabric, :select_field => select_fields[i], :boolean_field => boolean_fields[i]
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return all conditioned records' do
|
61
|
+
filter(:conditions => {'select_field' => 'hello'}).should == nth(0, 2, 3)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return all conditioned records' do
|
65
|
+
filter(:conditions => {'boolean_field' => false}).should == nth(1, 2, 4)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should stack conditions with end' do
|
69
|
+
filter(:conditions => {'select_field' => 'hello', 'boolean_field' => true}).should == nth(0, 3)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'order' do
|
75
|
+
|
76
|
+
before do
|
77
|
+
integer_fields = %w(2, 3, 5, 4, 1)
|
78
|
+
5.times { |i|
|
79
|
+
Fabricate fabric, :integer_field => integer_fields[i]
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should order records asc' do
|
84
|
+
filter(:order => 'integer_field').should == nth(4, 0, 1, 3, 2)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should order records asc' do
|
88
|
+
filter(:order => ['integer_field', :asc]).should == nth(4, 0, 1, 3, 2)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should order records desc' do
|
92
|
+
filter(:order => ['integer_field', :desc]).should == nth(2, 3, 1, 0, 4)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'lib/orm_adapter/base_shared'
|
3
|
+
|
4
|
+
describe "MongoidOrm" do
|
5
|
+
|
6
|
+
describe 'columns_hash' do
|
7
|
+
it 'should be proper' do
|
8
|
+
MongoidOrm::Primal.to_adapter.columns_hash.should == {
|
9
|
+
"_type" => {:type => :string},
|
10
|
+
"_id" => {:type => :"bson/object_id"},
|
11
|
+
"string_field" => {:type => :string},
|
12
|
+
"symbol_field" => {:type => :symbol},
|
13
|
+
"select_field" => {:type => :string},
|
14
|
+
"integer_field" => {:type => :integer},
|
15
|
+
"float_field" => {:type => :float},
|
16
|
+
"decimal_field" => {:type => :big_decimal},
|
17
|
+
"datetime_field" => {:type => :date_time},
|
18
|
+
"time_field" => {:type => :time},
|
19
|
+
"date_field" => {:type => :date},
|
20
|
+
"boolean_field" => {:type => :boolean},
|
21
|
+
"array_field" => {:type => :array},
|
22
|
+
"hash_field" => {:type => :hash},
|
23
|
+
"set_field" => {:type => :set},
|
24
|
+
"range_field" => {:type => :range}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'filter' do
|
30
|
+
it_should_behave_like "an adapter" do
|
31
|
+
def filter options = {}
|
32
|
+
model.to_adapter.filter(model, controller.index_fields, options).order([:_id, :asc]).all.to_a
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def nth *indexes
|
37
|
+
model.where.order([:_id, :asc]).all.to_a.values_at *indexes
|
38
|
+
end
|
39
|
+
|
40
|
+
let(:model) {MongoidOrm::Primal}
|
41
|
+
let(:fabric) {:mongoid_orm_primal}
|
42
|
+
let(:controller) {Orms::MongoidOrmPrimalsController}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -9,7 +9,7 @@ describe Puffer::Resource do
|
|
9
9
|
@mock_category = mock_model Category, :id => 42
|
10
10
|
|
11
11
|
get admin_category_path(@category)
|
12
|
-
resource =
|
12
|
+
resource = controller.resource
|
13
13
|
|
14
14
|
resource.collection_path.should == admin_categories_path
|
15
15
|
resource.member_path.should == admin_category_path(@category)
|
@@ -24,7 +24,7 @@ describe Puffer::Resource do
|
|
24
24
|
@mock_news = mock_model News, :id => 42
|
25
25
|
|
26
26
|
get admin_news_path(@news)
|
27
|
-
resource =
|
27
|
+
resource = controller.resource
|
28
28
|
|
29
29
|
resource.collection_path.should == admin_news_index_path
|
30
30
|
resource.member_path.should == admin_news_path(@news)
|
@@ -40,7 +40,7 @@ describe Puffer::Resource do
|
|
40
40
|
@mock_category = mock_model Category, :id => 42
|
41
41
|
|
42
42
|
get admin_post_category_path(@post, @category)
|
43
|
-
resource =
|
43
|
+
resource = controller.resource
|
44
44
|
|
45
45
|
resource.collection_path.should == admin_post_categories_path(@post)
|
46
46
|
resource.member_path.should == admin_post_category_path(@post, @category)
|
@@ -55,7 +55,7 @@ describe Puffer::Resource do
|
|
55
55
|
@profile = @user.profile
|
56
56
|
|
57
57
|
get admin_user_profile_path(@user)
|
58
|
-
resource =
|
58
|
+
resource = controller.resource
|
59
59
|
|
60
60
|
resource.collection_path.should == admin_user_profile_path(@user)
|
61
61
|
resource.member_path.should == admin_user_profile_path(@user)
|
@@ -69,7 +69,7 @@ describe Puffer::Resource do
|
|
69
69
|
@mock_tag = mock_model Tag, :id => 42
|
70
70
|
|
71
71
|
get admin_user_profile_tag_path(@user, @tag)
|
72
|
-
resource =
|
72
|
+
resource = controller.resource
|
73
73
|
|
74
74
|
resource.collection_path.should == admin_user_profile_tags_path(@user)
|
75
75
|
resource.member_path.should == admin_user_profile_tag_path(@user, @tag)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Tree" do
|
4
|
+
|
5
|
+
it "should generate proper tree" do
|
6
|
+
Rails.application.routes.resources_tree.map(&:to_struct).should == [
|
7
|
+
{:scope => :admin, :current => :users, :children => [:profile, :posts], :ancestors => []},
|
8
|
+
{:scope => :admin, :current => :profile, :children => [:tags], :ancestors => [:users]},
|
9
|
+
{:scope => :admin, :current => :tags, :children => [], :ancestors => [:users, :profile]},
|
10
|
+
{:scope => :admin, :current => :posts, :children => [:categories, :tags], :ancestors => [:users]},
|
11
|
+
{:scope => :admin, :current => :categories, :children => [], :ancestors => [:users, :posts]},
|
12
|
+
{:scope => :admin, :current => :tags, :children => [], :ancestors => [:users, :posts]},
|
13
|
+
{:scope => :admin, :current => :profiles, :children => [:tags], :ancestors => []},
|
14
|
+
{:scope => :admin, :current => :tags, :children => [], :ancestors => [:profiles]},
|
15
|
+
{:scope => :admin, :current => :posts, :children => [:user, :categories], :ancestors => []},
|
16
|
+
{:scope => :admin, :current => :user, :children => [], :ancestors => [:posts]},
|
17
|
+
{:scope => :admin, :current => :categories, :children => [], :ancestors => [:posts]},
|
18
|
+
{:scope => :admin, :current => :tagged_posts, :children => [:user, :categories, :tags], :ancestors => []},
|
19
|
+
{:scope => :admin, :current => :user, :children => [], :ancestors => [:tagged_posts]},
|
20
|
+
{:scope => :admin, :current => :categories, :children => [], :ancestors => [:tagged_posts]},
|
21
|
+
{:scope => :admin, :current => :tags, :children => [], :ancestors => [:tagged_posts]},
|
22
|
+
{:scope => :admin, :current => :categories, :children => [:posts], :ancestors => []},
|
23
|
+
{:scope => :admin, :current => :posts, :children => [], :ancestors => [:categories]},
|
24
|
+
{:scope => :admin, :current => :news, :children => [], :ancestors => []},
|
25
|
+
{:scope => :admin, :current => :puffer_users, :children => [], :ancestors => []},
|
26
|
+
{:scope => :orms, :current => :active_record_orm_primals, :children => [], :ancestors => []},
|
27
|
+
{:scope => :orms, :current => :mongoid_orm_primals, :children => [], :ancestors => []},
|
28
|
+
{:scope => :admin, :current => :session, :children => [], :ancestors => []}
|
29
|
+
]
|
30
|
+
end
|
31
|
+
end
|
data/spec/lib/resource_spec.rb
CHANGED
@@ -2,22 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Puffer::Resource do
|
4
4
|
|
5
|
-
def
|
6
|
-
ActiveSupport::HashWithIndifferentAccess.new(:
|
7
|
-
end
|
8
|
-
|
9
|
-
def plain_params
|
10
|
-
ActiveSupport::HashWithIndifferentAccess.new(:plural => true, :ancestors => [], :children => [])
|
5
|
+
def tree_node id, params = {}
|
6
|
+
ActiveSupport::HashWithIndifferentAccess.new(:puffer => Rails.application.routes.resources_tree[id]).merge(params)
|
11
7
|
end
|
12
8
|
|
13
9
|
it "no tree" do
|
14
|
-
resource = Puffer::Resource.new
|
10
|
+
resource = Puffer::Resource.new tree_node(17)
|
11
|
+
|
15
12
|
resource.parent.should be_nil
|
16
13
|
resource.children.should be_empty
|
17
14
|
end
|
18
15
|
|
19
16
|
it "full tree" do
|
20
|
-
resource = Puffer::Resource.new
|
17
|
+
resource = Puffer::Resource.new tree_node(3)
|
18
|
+
|
21
19
|
resource.parent.should_not be_nil
|
22
20
|
resource.ancestors.count.should == 1
|
23
21
|
resource.children.count.should == 2
|
@@ -26,11 +24,10 @@ describe Puffer::Resource do
|
|
26
24
|
describe "#parent" do
|
27
25
|
|
28
26
|
it "common params" do
|
29
|
-
resource = Puffer::Resource.new
|
30
|
-
parent = resource.parent
|
27
|
+
resource = Puffer::Resource.new tree_node(4, :user_id => 37, :post_id => 42)
|
31
28
|
|
32
|
-
parent.params.should ==
|
33
|
-
parent.
|
29
|
+
resource.parent.params.should == tree_node(3, :user_id => 37, :id => 42)
|
30
|
+
resource.parent.name.should == :posts
|
34
31
|
end
|
35
32
|
|
36
33
|
end
|
@@ -38,31 +35,32 @@ describe Puffer::Resource do
|
|
38
35
|
describe "#children" do
|
39
36
|
|
40
37
|
it "common params" do
|
41
|
-
resource = Puffer::Resource.new
|
38
|
+
resource = Puffer::Resource.new tree_node(3, :user_id => 37)
|
42
39
|
child = resource.children.first
|
43
40
|
|
44
|
-
child.params.should ==
|
45
|
-
child.
|
41
|
+
child.params.should == tree_node(4, :user_id => 37)
|
42
|
+
child.name.should == :categories
|
46
43
|
end
|
47
44
|
|
48
45
|
it "plural params" do
|
49
|
-
resource = Puffer::Resource.new
|
46
|
+
resource = Puffer::Resource.new tree_node(0)
|
50
47
|
child = resource.children.first
|
51
48
|
|
52
|
-
child.params.should ==
|
53
|
-
child.
|
49
|
+
child.params.should == tree_node(1)
|
50
|
+
child.name.should == :profile
|
54
51
|
end
|
55
52
|
|
56
53
|
it "params with :id" do
|
57
|
-
resource = Puffer::Resource.new
|
54
|
+
resource = Puffer::Resource.new tree_node(3, :user_id => 37, :id => 42)
|
58
55
|
child = resource.children.first
|
59
56
|
|
60
|
-
child.params.should ==
|
61
|
-
child.
|
57
|
+
child.params.should == tree_node(4, :user_id => 37, :post_id => 42)
|
58
|
+
child.name.should == :categories
|
62
59
|
end
|
63
60
|
|
64
61
|
end
|
65
|
-
|
62
|
+
|
63
|
+
=begin
|
66
64
|
describe "#collection" do
|
67
65
|
|
68
66
|
before do
|
@@ -71,21 +69,22 @@ describe Puffer::Resource do
|
|
71
69
|
end
|
72
70
|
|
73
71
|
it "no parent" do
|
74
|
-
resource = Puffer::Resource.new
|
72
|
+
resource = Puffer::Resource.new tree_node(15)
|
75
73
|
resource.collection.should == Category.limit(25).all
|
76
74
|
end
|
77
75
|
|
78
76
|
it "plural parent" do
|
79
|
-
resource = Puffer::Resource.new
|
77
|
+
resource = Puffer::Resource.new tree_node(10, :post_id => @post.id)
|
80
78
|
resource.collection.should == @post.categories.limit(25).all
|
81
79
|
end
|
82
80
|
|
83
81
|
it "singular parent" do
|
84
|
-
resource = Puffer::Resource.new
|
82
|
+
resource = Puffer::Resource.new tree_node(2, :user_id => @user.id)
|
85
83
|
resource.collection.should == @user.profile.tags.limit(25).all
|
86
84
|
end
|
87
85
|
|
88
86
|
end
|
87
|
+
=end
|
89
88
|
|
90
89
|
describe "#member" do
|
91
90
|
|
@@ -96,22 +95,22 @@ describe Puffer::Resource do
|
|
96
95
|
end
|
97
96
|
|
98
97
|
it "no parent" do
|
99
|
-
resource = Puffer::Resource.new
|
98
|
+
resource = Puffer::Resource.new tree_node(15, :id => @category.id)
|
100
99
|
resource.member.should == @category
|
101
100
|
end
|
102
101
|
|
103
102
|
it "plural parent" do
|
104
|
-
resource = Puffer::Resource.new
|
103
|
+
resource = Puffer::Resource.new tree_node(10, :post_id => @post.id, :id => @post.categories.first.id)
|
105
104
|
resource.member.should == @post.categories.first
|
106
105
|
end
|
107
106
|
|
108
107
|
it "singular" do
|
109
|
-
resource = Puffer::Resource.new
|
108
|
+
resource = Puffer::Resource.new tree_node(1, :user_id => @user.id)
|
110
109
|
resource.member.should == @user.profile
|
111
110
|
end
|
112
111
|
|
113
112
|
it "singular parent" do
|
114
|
-
resource = Puffer::Resource.new
|
113
|
+
resource = Puffer::Resource.new tree_node(2, :user_id => @user.id, :id => @user.profile.tags.first.id)
|
115
114
|
resource.member.should == @user.profile.tags.first
|
116
115
|
end
|
117
116
|
|
@@ -125,52 +124,52 @@ describe Puffer::Resource do
|
|
125
124
|
end
|
126
125
|
|
127
126
|
it "no parent" do
|
128
|
-
resource = Puffer::Resource.new
|
127
|
+
resource = Puffer::Resource.new tree_node(15)
|
129
128
|
resource.new_member.should be_new_record
|
130
129
|
resource.new_member.should be_instance_of(Category)
|
131
130
|
end
|
132
131
|
|
133
132
|
it "no parent with attributes" do
|
134
|
-
resource = Puffer::Resource.new
|
133
|
+
resource = Puffer::Resource.new tree_node(15, :category => {:title => 'my new title'})
|
135
134
|
resource.new_member.should be_new_record
|
136
135
|
resource.new_member.should be_instance_of(Category)
|
137
136
|
resource.new_member.title.should == 'my new title'
|
138
137
|
end
|
139
138
|
|
140
139
|
it "plural parent" do
|
141
|
-
resource = Puffer::Resource.new
|
140
|
+
resource = Puffer::Resource.new tree_node(10, :post_id => @post.id)
|
142
141
|
resource.new_member.should be_new_record
|
143
142
|
resource.new_member.should be_instance_of(Category)
|
144
143
|
end
|
145
144
|
|
146
145
|
it "plural parent with attributes" do
|
147
|
-
resource = Puffer::Resource.new
|
146
|
+
resource = Puffer::Resource.new tree_node(10, :post_id => @post.id, :category => {:title => 'my new title'})
|
148
147
|
resource.new_member.should be_new_record
|
149
148
|
resource.new_member.should be_instance_of(Category)
|
150
149
|
resource.new_member.title.should == 'my new title'
|
151
150
|
end
|
152
151
|
|
153
152
|
it "singular" do
|
154
|
-
resource = Puffer::Resource.new
|
153
|
+
resource = Puffer::Resource.new tree_node(1, :user_id => @user.id)
|
155
154
|
resource.new_member.should be_new_record
|
156
155
|
resource.new_member.should be_instance_of(Profile)
|
157
156
|
end
|
158
157
|
|
159
158
|
it "singular with attributes" do
|
160
|
-
resource = Puffer::Resource.new
|
159
|
+
resource = Puffer::Resource.new tree_node(1, :user_id => @user.id, :profile => {:name => 'my new name'})
|
161
160
|
resource.new_member.should be_new_record
|
162
161
|
resource.new_member.should be_instance_of(Profile)
|
163
162
|
resource.new_member.name.should == 'my new name'
|
164
163
|
end
|
165
164
|
|
166
165
|
it "singular parent" do
|
167
|
-
resource = Puffer::Resource.new
|
166
|
+
resource = Puffer::Resource.new tree_node(2, :user_id => @user.id)
|
168
167
|
resource.new_member.should be_new_record
|
169
168
|
resource.new_member.should be_instance_of(Tag)
|
170
169
|
end
|
171
170
|
|
172
171
|
it "singular parent with attributes" do
|
173
|
-
resource = Puffer::Resource.new
|
172
|
+
resource = Puffer::Resource.new tree_node(2, :user_id => @user.id, :tag => {:name => 'my new name'})
|
174
173
|
resource.new_member.should be_new_record
|
175
174
|
resource.new_member.should be_instance_of(Tag)
|
176
175
|
resource.new_member.name.should == 'my new name'
|