outpost-cms 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +295 -0
- data/Rakefile +26 -0
- data/app/assets/images/glyphicons-halflings-red.png +0 -0
- data/app/assets/javascripts/outpost/application.js +1 -0
- data/app/assets/javascripts/outpost/auto_slug_field.js.coffee +53 -0
- data/app/assets/javascripts/outpost/base.js.coffee +1 -0
- data/app/assets/javascripts/outpost/date_time_input.js.coffee +108 -0
- data/app/assets/javascripts/outpost/field_counter.js.coffee +93 -0
- data/app/assets/javascripts/outpost/field_manager.js.coffee +37 -0
- data/app/assets/javascripts/outpost/global_plugins.js.coffee +87 -0
- data/app/assets/javascripts/outpost/index_manager.js.coffee +88 -0
- data/app/assets/javascripts/outpost/notification.js.coffee +46 -0
- data/app/assets/javascripts/outpost/preview.js.coffee +60 -0
- data/app/assets/javascripts/outpost/templates/date_field.jst.eco +3 -0
- data/app/assets/javascripts/outpost/templates/loading.jst.eco +11 -0
- data/app/assets/javascripts/outpost/templates/slug_generate_button.jst.eco +1 -0
- data/app/assets/javascripts/outpost/templates/time_field.jst.eco +3 -0
- data/app/assets/javascripts/outpost/templates.js +1 -0
- data/app/assets/javascripts/outpost.js +32 -0
- data/app/assets/stylesheets/outpost/_base.css.scss +127 -0
- data/app/assets/stylesheets/outpost/_edit.css.scss +13 -0
- data/app/assets/stylesheets/outpost/_forms.css.scss +116 -0
- data/app/assets/stylesheets/outpost/_index.css.scss +68 -0
- data/app/assets/stylesheets/outpost/_utility.css.scss +16 -0
- data/app/assets/stylesheets/outpost/application.css.scss +1 -0
- data/app/assets/stylesheets/outpost/bootstrap/bootstrap.css.scss +49 -0
- data/app/assets/stylesheets/outpost/bootstrap/datepicker.css.scss +301 -0
- data/app/assets/stylesheets/outpost.css.scss +14 -0
- data/app/controllers/outpost/application_controller.rb +40 -0
- data/app/controllers/outpost/base_controller.rb +3 -0
- data/app/controllers/outpost/errors_controller.rb +9 -0
- data/app/controllers/outpost/home_controller.rb +2 -0
- data/app/controllers/outpost/resource_controller.rb +12 -0
- data/app/controllers/outpost/sessions_controller.rb +36 -0
- data/app/helpers/authorization_helper.rb +44 -0
- data/app/helpers/list_helper.rb +243 -0
- data/app/helpers/outpost_helper.rb +49 -0
- data/app/helpers/render_helper.rb +41 -0
- data/app/helpers/utility_helper.rb +136 -0
- data/app/inputs/date_time_input.rb +12 -0
- data/app/models/permission.rb +18 -0
- data/app/models/user_permission.rb +4 -0
- data/app/views/kaminari/bootstrap/_first_page.html.erb +3 -0
- data/app/views/kaminari/bootstrap/_gap.html.erb +3 -0
- data/app/views/kaminari/bootstrap/_last_page.html.erb +3 -0
- data/app/views/kaminari/bootstrap/_next_page.html.erb +3 -0
- data/app/views/kaminari/bootstrap/_page.html.erb +3 -0
- data/app/views/kaminari/bootstrap/_paginator.html.erb +17 -0
- data/app/views/kaminari/bootstrap/_prev_page.html.erb +3 -0
- data/app/views/layouts/outpost/application.html.erb +101 -0
- data/app/views/layouts/outpost/minimal.html.erb +26 -0
- data/app/views/outpost/errors/error_404.html.erb +1 -0
- data/app/views/outpost/errors/error_500.html.erb +8 -0
- data/app/views/outpost/home/dashboard.html.erb +1 -0
- data/app/views/outpost/resource/_errors.html.erb +11 -0
- data/app/views/outpost/resource/_extra_fields.html.erb +1 -0
- data/app/views/outpost/resource/_form_fields.html.erb +9 -0
- data/app/views/outpost/resource/edit.html.erb +44 -0
- data/app/views/outpost/resource/index.html.erb +22 -0
- data/app/views/outpost/resource/new.html.erb +21 -0
- data/app/views/outpost/resource/search.html.erb +1 -0
- data/app/views/outpost/resource/show.html.erb +1 -0
- data/app/views/outpost/sessions/new.html.erb +16 -0
- data/app/views/outpost/shared/_add_link.html.erb +1 -0
- data/app/views/outpost/shared/_breadcrumbs.html.erb +15 -0
- data/app/views/outpost/shared/_cancel_link.html.erb +1 -0
- data/app/views/outpost/shared/_columns.html.erb +5 -0
- data/app/views/outpost/shared/_filters.html.erb +16 -0
- data/app/views/outpost/shared/_flash_messages.html.erb +6 -0
- data/app/views/outpost/shared/_form_block.html.erb +18 -0
- data/app/views/outpost/shared/_form_nav.html.erb +12 -0
- data/app/views/outpost/shared/_headers.html.erb +16 -0
- data/app/views/outpost/shared/_index_header.html.erb +4 -0
- data/app/views/outpost/shared/_list_table.html.erb +7 -0
- data/app/views/outpost/shared/_modal.html.erb +16 -0
- data/app/views/outpost/shared/_navigation.html.erb +31 -0
- data/app/views/outpost/shared/_notice.html.erb +1 -0
- data/app/views/outpost/shared/_pagination.html.erb +2 -0
- data/app/views/outpost/shared/_preview_errors.html.erb +9 -0
- data/app/views/outpost/shared/_submit_row.html.erb +50 -0
- data/config/routes.rb +4 -0
- data/lib/action_view/helpers/form_builder.rb +71 -0
- data/lib/outpost/breadcrumbs.rb +73 -0
- data/lib/outpost/config.rb +63 -0
- data/lib/outpost/controller/actions.rb +72 -0
- data/lib/outpost/controller/authentication.rb +34 -0
- data/lib/outpost/controller/authorization.rb +28 -0
- data/lib/outpost/controller/callbacks.rb +14 -0
- data/lib/outpost/controller/custom_errors.rb +41 -0
- data/lib/outpost/controller/filtering.rb +22 -0
- data/lib/outpost/controller/helpers.rb +52 -0
- data/lib/outpost/controller/ordering.rb +46 -0
- data/lib/outpost/controller/preferences.rb +71 -0
- data/lib/outpost/controller.rb +123 -0
- data/lib/outpost/engine.rb +10 -0
- data/lib/outpost/helpers/naming.rb +22 -0
- data/lib/outpost/helpers.rb +6 -0
- data/lib/outpost/hook.rb +35 -0
- data/lib/outpost/list/base.rb +78 -0
- data/lib/outpost/list/column.rb +24 -0
- data/lib/outpost/list/filter.rb +37 -0
- data/lib/outpost/list.rb +15 -0
- data/lib/outpost/model/authentication.rb +34 -0
- data/lib/outpost/model/authorization.rb +32 -0
- data/lib/outpost/model/identifier.rb +39 -0
- data/lib/outpost/model/methods.rb +23 -0
- data/lib/outpost/model/naming.rb +63 -0
- data/lib/outpost/model/routing.rb +138 -0
- data/lib/outpost/model/serializer.rb +27 -0
- data/lib/outpost/model.rb +22 -0
- data/lib/outpost/test.rb +21 -0
- data/lib/outpost/version.rb +3 -0
- data/lib/outpost-cms.rb +2 -0
- data/lib/outpost.rb +80 -0
- data/lib/tasks/outpost_tasks.rake +7 -0
- data/spec/controllers/authentication_spec.rb +62 -0
- data/spec/controllers/sessions_controller_spec.rb +99 -0
- data/spec/factories.rb +31 -0
- data/spec/helpers/authorization_helper_spec.rb +47 -0
- data/spec/helpers/list_helper_spec.rb +74 -0
- data/spec/helpers/outpost_helper_spec.rb +5 -0
- data/spec/helpers/render_helper_spec.rb +19 -0
- data/spec/helpers/utility_helper_spec.rb +53 -0
- data/spec/internal/app/controllers/application_controller.rb +3 -0
- data/spec/internal/app/controllers/outpost/people_controller.rb +23 -0
- data/spec/internal/app/controllers/outpost/pidgeons_controller.rb +5 -0
- data/spec/internal/app/controllers/people_controller.rb +9 -0
- data/spec/internal/app/controllers/pidgeons_controller.rb +3 -0
- data/spec/internal/app/models/person.rb +10 -0
- data/spec/internal/app/models/pidgeon.rb +3 -0
- data/spec/internal/app/models/post.rb +4 -0
- data/spec/internal/app/models/user.rb +4 -0
- data/spec/internal/app/views/people/index.html.erb +7 -0
- data/spec/internal/app/views/people/show.html.erb +1 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/configuration.rb +3 -0
- data/spec/internal/config/initializers/outpost.rb +6 -0
- data/spec/internal/config/routes.rb +16 -0
- data/spec/internal/db/combustion_test.sqlite +0 -0
- data/spec/internal/db/schema.rb +44 -0
- data/spec/internal/db/seeds.rb +14 -0
- data/spec/internal/log/test.log +59277 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/breadcrumbs_spec.rb +54 -0
- data/spec/lib/config_spec.rb +76 -0
- data/spec/lib/controller/actions_spec.rb +5 -0
- data/spec/lib/controller/authorization_spec.rb +4 -0
- data/spec/lib/controller/callbacks_spec.rb +31 -0
- data/spec/lib/controller/helpers_spec.rb +33 -0
- data/spec/lib/controller_spec.rb +25 -0
- data/spec/lib/helpers/naming_spec.rb +10 -0
- data/spec/lib/hook_spec.rb +13 -0
- data/spec/lib/list/base_spec.rb +96 -0
- data/spec/lib/list/column_spec.rb +46 -0
- data/spec/lib/list/filter_spec.rb +44 -0
- data/spec/lib/model/authentication_spec.rb +29 -0
- data/spec/lib/model/authorization_spec.rb +66 -0
- data/spec/lib/model/identifier_spec.rb +51 -0
- data/spec/lib/model/methods_spec.rb +8 -0
- data/spec/lib/model/naming_spec.rb +55 -0
- data/spec/lib/model/routing_spec.rb +166 -0
- data/spec/lib/model/serializer_spec.rb +13 -0
- data/spec/lib/outpost_spec.rb +34 -0
- data/spec/models/permission_spec.rb +10 -0
- data/spec/models/user_permission_spec.rb +4 -0
- data/spec/spec_helper.rb +22 -0
- metadata +411 -0
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Breadcrumb do
|
4
|
+
it "has a title and a link" do
|
5
|
+
breadcrumb = Outpost::Breadcrumb.new
|
6
|
+
breadcrumb.should respond_to :title
|
7
|
+
breadcrumb.should respond_to :link
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#------------------
|
12
|
+
|
13
|
+
describe Outpost::Breadcrumbs do
|
14
|
+
describe "#breadcrumb" do
|
15
|
+
context "ActionController::Base class" do
|
16
|
+
let(:controller) { Outpost::PeopleController.new }
|
17
|
+
|
18
|
+
it "has the breadcrumbs helper methods" do
|
19
|
+
Outpost::PeopleController._helper_methods.should include :breadcrumbs
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has both a title and link when both specified" do
|
23
|
+
controller.breadcrumb "Title", "/some/path"
|
24
|
+
controller.breadcrumbs.size.should eq 1
|
25
|
+
controller.breadcrumbs.first.title.should eq "Title"
|
26
|
+
controller.breadcrumbs.first.link.should eq "/some/path"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "only has a title when no link is specified" do
|
30
|
+
controller.breadcrumb "Title"
|
31
|
+
controller.breadcrumbs.size.should eq 1
|
32
|
+
controller.breadcrumbs.first.title.should eq "Title"
|
33
|
+
controller.breadcrumbs.first.link.should eq nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "accepts multiple breadcrumbs" do
|
37
|
+
controller.breadcrumb "Title", "/some/path", "Other", nil, "Page"
|
38
|
+
controller.breadcrumbs.size.should eq 3
|
39
|
+
controller.breadcrumbs[0].title.should eq "Title"
|
40
|
+
controller.breadcrumbs[0].link.should eq "/some/path"
|
41
|
+
controller.breadcrumbs[1].title.should eq "Other"
|
42
|
+
controller.breadcrumbs[1].link.should eq nil
|
43
|
+
controller.breadcrumbs[2].title.should eq "Page"
|
44
|
+
controller.breadcrumbs[2].link.should eq nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "other class" do
|
49
|
+
it "doesn't complain about helper_method" do
|
50
|
+
class CoolGuy; include Outpost::Breadcrumbs; end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Config do
|
4
|
+
describe "::configure" do
|
5
|
+
it "accepts a block with the config object" do
|
6
|
+
Outpost::Config.configure do |config|
|
7
|
+
config.should be_a Outpost::Config
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "sets Outpost.config to the new Config object" do
|
12
|
+
Outpost.config.should be_a Outpost::Config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#----------------------
|
17
|
+
|
18
|
+
describe "#registered_models" do
|
19
|
+
it "returns an empty array if nothing is set" do
|
20
|
+
original_value = Outpost.config.registered_models
|
21
|
+
|
22
|
+
Outpost.config.registered_models = nil
|
23
|
+
Outpost.config.registered_models.should eq []
|
24
|
+
|
25
|
+
Outpost.config.registered_models = original_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#----------------------
|
30
|
+
|
31
|
+
describe "#title_attributes" do
|
32
|
+
it "returns the defaults plus :simple_title if nothing is set" do
|
33
|
+
stub_const("Outpost::Config::DEFAULTS", { title_attributes: [:title] })
|
34
|
+
Outpost.config.title_attributes = nil
|
35
|
+
Outpost.config.title_attributes.should eq [:title, :simple_title]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "always includes simple_title" do
|
39
|
+
stub_const("Outpost::Config::DEFAULTS", { title_attributes: [] })
|
40
|
+
Outpost.config.title_attributes = nil
|
41
|
+
Outpost.config.title_attributes.should eq [:simple_title]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
#----------------------
|
46
|
+
|
47
|
+
describe "#excluded_form_fields" do
|
48
|
+
it "returns the defaults if nothing is set" do
|
49
|
+
stub_const("Outpost::Config::DEFAULTS", { excluded_form_fields: [:title] })
|
50
|
+
Outpost.config.excluded_form_fields = nil
|
51
|
+
Outpost.config.excluded_form_fields.should eq [:title]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "always included the defaults" do
|
55
|
+
stub_const("Outpost::Config::DEFAULTS", { excluded_form_fields: [:title] })
|
56
|
+
Outpost.config.excluded_form_fields = [:body, :title]
|
57
|
+
Outpost.config.excluded_form_fields.should eq [:body, :title]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#----------------------
|
62
|
+
|
63
|
+
describe "#excluded_list_columns" do
|
64
|
+
it "returns the defaults if nothing is set" do
|
65
|
+
stub_const("Outpost::Config::DEFAULTS", { excluded_list_columns: ["title"] })
|
66
|
+
Outpost.config.excluded_list_columns = nil
|
67
|
+
Outpost.config.excluded_list_columns.should eq ["title"]
|
68
|
+
end
|
69
|
+
|
70
|
+
it "always included the defaults" do
|
71
|
+
stub_const("Outpost::Config::DEFAULTS", { excluded_list_columns: ["title"] })
|
72
|
+
Outpost.config.excluded_list_columns = ["body", "title"]
|
73
|
+
Outpost.config.excluded_list_columns.should eq ["body", "title"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Controller::Callbacks do
|
4
|
+
describe "#get_record" do
|
5
|
+
pending
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#get_records" do
|
9
|
+
pending
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#order_records' do
|
13
|
+
pending
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#set_order' do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#set_sort_mode' do
|
21
|
+
pending
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#remove_preferences' do
|
25
|
+
pending
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#filter_records' do
|
29
|
+
pending
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Controller::Helpers do
|
4
|
+
let(:controller) { PeopleController.new }
|
5
|
+
|
6
|
+
describe "#model" do
|
7
|
+
it "adds model as a helper" do
|
8
|
+
controller._helper_methods.should include :model
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#------------------------
|
13
|
+
|
14
|
+
describe "#notice" do
|
15
|
+
context "HTML request" do
|
16
|
+
it "adds the notice to flash" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "non-HTML request" do
|
22
|
+
it "doesn't add anything to flash" do
|
23
|
+
pending
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#------------------------
|
29
|
+
|
30
|
+
describe '#preference' do
|
31
|
+
pending
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Controller do
|
4
|
+
describe '::fields' do
|
5
|
+
let(:controller) { Outpost::PeopleController.new }
|
6
|
+
|
7
|
+
it 'sets default fields' do
|
8
|
+
controller.fields.should include "name"
|
9
|
+
controller.fields.should include "email"
|
10
|
+
controller.fields.should_not include "id"
|
11
|
+
controller.fields.should_not include "updated_at"
|
12
|
+
controller.fields.should_not include "created_at"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "::list" do
|
17
|
+
let(:controller) { PidgeonsController.new }
|
18
|
+
|
19
|
+
it "defines a list if it hasn't been already" do
|
20
|
+
PidgeonsController.instance_variable_get(:@list).should eq nil
|
21
|
+
list = PidgeonsController.list
|
22
|
+
list.should be_a Outpost::List::Base
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Helpers::Naming do
|
4
|
+
describe "::to_class" do
|
5
|
+
it "turns the controller param into its corresponding class" do
|
6
|
+
stub_const("Person", nil)
|
7
|
+
Outpost::Helpers::Naming.to_class("admin/people").should eq Person
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::List::Base do
|
4
|
+
|
5
|
+
#--------------
|
6
|
+
|
7
|
+
let(:model) { Person }
|
8
|
+
|
9
|
+
describe "initialize" do
|
10
|
+
context "with block" do
|
11
|
+
it "yields and sets attributes" do
|
12
|
+
list = Outpost::List::Base.new model do |l|
|
13
|
+
l.default_order = "omg"
|
14
|
+
l.default_sort_mode = "wtf"
|
15
|
+
l.per_page = 999
|
16
|
+
end
|
17
|
+
|
18
|
+
list.default_order.should eq "omg"
|
19
|
+
list.default_sort_mode.should eq "wtf"
|
20
|
+
list.per_page.should eq 999
|
21
|
+
end
|
22
|
+
|
23
|
+
it "sets any attributes that weren't set in the block" do
|
24
|
+
list = Outpost::List::Base.new model do |l|
|
25
|
+
l.default_order = "omg"
|
26
|
+
end
|
27
|
+
|
28
|
+
list.default_order.should eq "omg"
|
29
|
+
list.default_sort_mode.should eq Outpost::List::DEFAULT_SORT_MODE
|
30
|
+
list.per_page.should eq Outpost::List::DEFAULT_PER_PAGE
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "without block" do
|
35
|
+
it "sets order to default" do
|
36
|
+
list = Outpost::List::Base.new(model)
|
37
|
+
list.default_order.should eq Outpost::List::DEFAULT_ORDER
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets sort_mode to default" do
|
41
|
+
list = Outpost::List::Base.new(model)
|
42
|
+
list.default_sort_mode.should eq Outpost::List::DEFAULT_SORT_MODE
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sets per_page to default" do
|
46
|
+
list = Outpost::List::Base.new(model)
|
47
|
+
list.per_page.should eq Outpost::List::DEFAULT_PER_PAGE
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#--------------
|
53
|
+
|
54
|
+
describe "column" do
|
55
|
+
let(:list) { Outpost::List::Base.new(model) }
|
56
|
+
|
57
|
+
it "creates a new column object and adds it to the columns" do
|
58
|
+
column = list.column("name")
|
59
|
+
column.should be_a Outpost::List::Column
|
60
|
+
list.columns.should eq Hash["name" => column]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "sets the column's list to self" do
|
64
|
+
column = list.column("name")
|
65
|
+
column.list.should eq list
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#--------------
|
70
|
+
|
71
|
+
describe "filter" do
|
72
|
+
let(:list) { Outpost::List::Base.new(model) }
|
73
|
+
|
74
|
+
it "creates a new filter object and adds it to the filters" do
|
75
|
+
filter = list.filter("name")
|
76
|
+
filter.should be_a Outpost::List::Filter
|
77
|
+
list.filters.should eq Hash["name" => filter]
|
78
|
+
end
|
79
|
+
|
80
|
+
it "sets the filters's list to self" do
|
81
|
+
filter = list.filter("name")
|
82
|
+
filter.list.should eq list
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#--------------
|
87
|
+
|
88
|
+
describe "per_page=" do
|
89
|
+
let(:list) { Outpost::List::Base.new(model) }
|
90
|
+
|
91
|
+
it "sets @per_page to passed-in value as an integer if specified" do
|
92
|
+
list.per_page = "99"
|
93
|
+
list.per_page.should eq 99
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::List::Column do
|
4
|
+
let(:model) { Person }
|
5
|
+
|
6
|
+
#----------------
|
7
|
+
|
8
|
+
describe "initialization" do
|
9
|
+
let(:list) { Outpost::List::Base.new(model) }
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
list.column "name", {
|
13
|
+
:quick_edit => true,
|
14
|
+
:display => :display_full_name,
|
15
|
+
:header => "Full Name"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets position" do
|
20
|
+
list.column "body"
|
21
|
+
list.columns["name"].position.should eq 0
|
22
|
+
list.columns["body"].position.should eq 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it "figures out header if none specified" do
|
26
|
+
published_column = list.column :published_at
|
27
|
+
published_column.header.should eq :published_at.to_s.titleize
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sets quick_edit" do
|
31
|
+
col = list.columns["name"]
|
32
|
+
col.quick_edit.should eq true
|
33
|
+
col.quick_edit?.should eq true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "sets sortable" do
|
37
|
+
col = list.columns["name"]
|
38
|
+
col.sortable.should eq false
|
39
|
+
col.sortable?.should eq false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets default_sort_mode to default if not specified" do
|
43
|
+
list.columns["name"].default_sort_mode.should eq Outpost::List::DEFAULT_SORT_MODE
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::List::Filter do
|
4
|
+
let(:model) { Person }
|
5
|
+
|
6
|
+
#----------------
|
7
|
+
|
8
|
+
describe "initialization" do
|
9
|
+
let(:list) { Outpost::List::Base.new(model) }
|
10
|
+
|
11
|
+
before :each do
|
12
|
+
list.filter "is_public", {
|
13
|
+
:title => "Public?",
|
14
|
+
:collection => :boolean
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "figures out title if none specified" do
|
19
|
+
status_filter = list.filter "status"
|
20
|
+
status_filter.title.should eq "status".titleize
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "setting collection" do
|
24
|
+
context "when collection is nil" do
|
25
|
+
# Doesn't currently do anything
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when collection is Proc" do
|
29
|
+
it "sets the collection to the proc as-is" do
|
30
|
+
id_proc = -> { self.id }
|
31
|
+
id_filter = list.filter "id", collection: id_proc
|
32
|
+
id_filter.collection.should eq id_proc
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when collection is symbol" do
|
37
|
+
it "uses the corresponding method" do
|
38
|
+
is_visible_filter = list.filter "is_visible", collection: :boolean
|
39
|
+
is_visible_filter.collection.call.should eq Outpost::List::Filter::BOOLEAN_COLLECT
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Model::Authentication do
|
4
|
+
describe "::authenticate" do
|
5
|
+
it "returns the user if the username and password are correct" do
|
6
|
+
user = create :user, password: "secret"
|
7
|
+
User.authenticate(user.email, "secret").should eq user
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns false if the password is incorrect" do
|
11
|
+
user = create :user, password: "secret"
|
12
|
+
User.authenticate(user.email, "wrong").should eq false
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns false if the username isn't found" do
|
16
|
+
user = create :user, email: "bricker@kpcc.org"
|
17
|
+
User.authenticate("wrong", "secret").should eq false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#----------------
|
22
|
+
|
23
|
+
describe "downcase_email" do
|
24
|
+
it "downcases the e-mail before validating and saving a user" do
|
25
|
+
user = create :user, email: "SomeEmail@email.com"
|
26
|
+
user.email.should eq "someemail@email.com"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Model::Authorization do
|
4
|
+
describe "#can_manage?" do
|
5
|
+
let(:permission1) { create :permission, resource: "Post" }
|
6
|
+
let(:permission2) { create :permission, resource: "Pidgeon" }
|
7
|
+
|
8
|
+
context "superuser" do
|
9
|
+
let(:superuser) { create :user, is_superuser: true }
|
10
|
+
|
11
|
+
it "is true for superusers" do
|
12
|
+
superuser.can_manage?("anything").should eq true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "non-superuser" do
|
17
|
+
let(:user) { create :user, is_superuser: false }
|
18
|
+
|
19
|
+
it "is true if the user can manage all of the passed-in resources" do
|
20
|
+
user.permissions += [permission1, permission2]
|
21
|
+
user.can_manage?(Post, Pidgeon).should eq true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "is false if the user can manage only some of the passed-in resources" do
|
25
|
+
user.permissions += [permission1]
|
26
|
+
user.can_manage?(Post, Pidgeon).should eq false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#--------------------
|
32
|
+
|
33
|
+
describe '#allowed_resource' do
|
34
|
+
let(:permission1) { create :permission, resource: "Post" }
|
35
|
+
let(:permission2) { create :permission, resource: "Pidgeon" }
|
36
|
+
|
37
|
+
context 'superuser' do
|
38
|
+
before :each do
|
39
|
+
# eager load
|
40
|
+
permission1
|
41
|
+
permission2
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:superuser) { create :user, is_superuser: true }
|
45
|
+
|
46
|
+
it 'returns all Permissions' do
|
47
|
+
superuser.allowed_resources.should eq [Post, Pidgeon]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'user' do
|
52
|
+
let(:user) { create :user, is_superuser: false }
|
53
|
+
|
54
|
+
it "returns only that user's permissions" do
|
55
|
+
user.permissions = [permission1]
|
56
|
+
user.allowed_resources.should eq [Post]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "ignores missing constants" do
|
60
|
+
bad_permission = create :permission, resource: "NotAModel"
|
61
|
+
user.permissions = [permission1, bad_permission]
|
62
|
+
user.allowed_resources.should eq [Post]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Model::Identifier do
|
4
|
+
describe "::content_key" do
|
5
|
+
it "uses the table name if it responds to it" do
|
6
|
+
Person.stub(:table_name) { "people_and_stuff" }
|
7
|
+
Person.content_key.should eq "people/and/stuff"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "tableizes the classname if no table" do
|
11
|
+
Person.content_key.should eq "people"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#----------------
|
16
|
+
|
17
|
+
describe "::route_key" do
|
18
|
+
it "uses ActiveModel's route_key method" do
|
19
|
+
ActiveModel::Naming.should_receive(:route_key)
|
20
|
+
Person.route_key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
#----------------
|
25
|
+
|
26
|
+
describe "::singular_route_key" do
|
27
|
+
it "uses ActiveModel's singular_route_key method" do
|
28
|
+
ActiveModel::Naming.should_receive(:singular_route_key)
|
29
|
+
Person.singular_route_key
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#----------------
|
34
|
+
|
35
|
+
describe "#obj_key" do
|
36
|
+
context "for persisted record" do
|
37
|
+
it "uses the class's content_key, the record's ID, and joins by :" do
|
38
|
+
person = Person.create(name: "Bryan")
|
39
|
+
person.id.should_not be_blank
|
40
|
+
person.obj_key.should eq "people:#{person.id}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "for new record" do
|
45
|
+
it "uses new in the key" do
|
46
|
+
person = Person.new(name: "Bryan")
|
47
|
+
person.obj_key.should eq "people:new"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Outpost::Model::Naming do
|
4
|
+
describe "::to_title" do
|
5
|
+
it "returns the titleized class name" do
|
6
|
+
Person.to_title.should eq "Person"
|
7
|
+
Person.stub(:name) { "SomeModule::Person" }
|
8
|
+
Person.to_title.should eq "Person"
|
9
|
+
Person.stub(:name) { "SomeModule::PersonThing"}
|
10
|
+
Person.to_title.should eq "Person Thing"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#----------------
|
15
|
+
|
16
|
+
describe "#title_method" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
#----------------
|
21
|
+
|
22
|
+
describe "#to_title" do
|
23
|
+
it "uses one of the specified title attributes if available" do
|
24
|
+
Outpost.config.title_attributes = [:name]
|
25
|
+
person = Person.create(name: "Bryan Ricker")
|
26
|
+
person.to_title.should eq "Bryan Ricker"
|
27
|
+
end
|
28
|
+
|
29
|
+
# This is actually being handled by config.title_attributes being injected
|
30
|
+
# with :simple_title... we can test it here anyways
|
31
|
+
it "falls back to a simple_title if none of the attributes match" do
|
32
|
+
Outpost.config.title_attributes = [:title]
|
33
|
+
person = Person.create(id: 1, name: "Bryan Ricker")
|
34
|
+
person.should_receive(:simple_title).and_return("Simple Title")
|
35
|
+
person.to_title.should eq "Simple Title"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#----------------
|
40
|
+
|
41
|
+
describe "#simple_title" do
|
42
|
+
it "returns a simple name for a new object" do
|
43
|
+
person = Person.new(id: 1, name: "Bryan Ricker")
|
44
|
+
person.new_record?.should be_true
|
45
|
+
person.simple_title.should eq "New Person"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns a simple name for a persisted object" do
|
49
|
+
person = Person.create(name: "Bryan Ricker")
|
50
|
+
person.id.should be_present
|
51
|
+
person.new_record?.should be_false
|
52
|
+
person.simple_title.should eq "Person ##{person.id}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|