rails_admin 0.1.2 → 0.2.0
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 +18 -20
- data/README.md +8 -1
- data/app/assets/javascripts/rails_admin/ra.widgets.coffee +5 -4
- data/app/assets/stylesheets/rails_admin/base/theming.css.scss +4 -4
- data/app/controllers/rails_admin/main_controller.rb +11 -2
- data/app/helpers/rails_admin/application_helper.rb +1 -1
- data/app/helpers/rails_admin/form_builder.rb +3 -3
- data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +4 -4
- data/app/views/rails_admin/main/_form_filtering_select.html.haml +2 -2
- data/app/views/rails_admin/main/_form_nested_one.html.haml +1 -1
- data/app/views/rails_admin/main/_form_text.html.haml +2 -1
- data/app/views/rails_admin/main/export.html.haml +2 -2
- data/app/views/rails_admin/main/index.html.haml +5 -5
- data/app/views/rails_admin/main/show.html.haml +1 -1
- data/lib/generators/rails_admin/templates/initializer.erb +5 -5
- data/lib/rails_admin/abstract_model.rb +1 -0
- data/lib/rails_admin/config.rb +1 -1
- data/lib/rails_admin/config/actions/base.rb +1 -1
- data/lib/rails_admin/config/actions/edit.rb +5 -4
- data/lib/rails_admin/config/actions/new.rb +5 -4
- data/lib/rails_admin/config/fields/association.rb +10 -10
- data/lib/rails_admin/config/fields/base.rb +10 -4
- data/lib/rails_admin/config/fields/types/belongs_to_association.rb +2 -2
- data/lib/rails_admin/config/fields/types/boolean.rb +4 -4
- data/lib/rails_admin/config/fields/types/bson_object_id.rb +4 -4
- data/lib/rails_admin/config/fields/types/carrierwave.rb +3 -3
- data/lib/rails_admin/config/fields/types/datetime.rb +5 -5
- data/lib/rails_admin/config/fields/types/enum.rb +5 -5
- data/lib/rails_admin/config/fields/types/file_upload.rb +10 -6
- data/lib/rails_admin/config/fields/types/has_many_association.rb +1 -1
- data/lib/rails_admin/config/fields/types/has_one_association.rb +3 -3
- data/lib/rails_admin/config/fields/types/integer.rb +1 -1
- data/lib/rails_admin/config/fields/types/paperclip.rb +2 -2
- data/lib/rails_admin/config/fields/types/polymorphic_association.rb +8 -4
- data/lib/rails_admin/config/fields/types/serialized.rb +2 -2
- data/lib/rails_admin/config/fields/types/string.rb +3 -3
- data/lib/rails_admin/config/fields/types/text.rb +22 -15
- data/lib/rails_admin/config/fields/types/time.rb +1 -1
- data/lib/rails_admin/config/hideable.rb +1 -1
- data/lib/rails_admin/config/model.rb +4 -0
- data/lib/rails_admin/config/sections/modal.rb +1 -1
- data/lib/rails_admin/engine.rb +1 -1
- data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +2 -1
- data/lib/rails_admin/support/csv_converter.rb +1 -1
- data/lib/rails_admin/version.rb +2 -2
- data/lib/rails_admin/version.rbc +582 -0
- data/lib/tasks/rails_admin.rake +2 -2
- data/spec/controllers/main_controller_spec.rb +113 -45
- data/spec/dummy_app/Gemfile +11 -25
- data/spec/dummy_app/Gemfile.lock +214 -0
- data/spec/dummy_app/app/active_record/comment.rb +1 -1
- data/spec/dummy_app/app/active_record/field_test.rb +0 -1
- data/spec/dummy_app/config/initializers/strong_parameters.rb +2 -0
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +97612 -0
- data/spec/helpers/application_helper_spec.rb +24 -24
- data/spec/helpers/form_builder_spec.rb +4 -4
- data/spec/integration/authorization/cancan_spec.rb +3 -3
- data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +2 -2
- data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +2 -2
- data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +9 -9
- data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -1
- data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +4 -4
- data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +9 -9
- data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +10 -10
- data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +5 -5
- data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +32 -25
- data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +8 -8
- data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +3 -3
- data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +6 -6
- data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +13 -13
- data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +97 -76
- data/spec/integration/config/list/rails_admin_config_list_spec.rb +32 -32
- data/spec/integration/config/show/rails_admin_config_show_spec.rb +23 -23
- data/spec/integration/history/rails_admin_history_spec.rb +6 -6
- data/spec/integration/rails_admin_spec.rb +17 -17
- data/spec/integration/relation_spec.rb +7 -7
- data/spec/unit/abstract_model_spec.rb +11 -5
- data/spec/unit/active_record_extension_spec.rb +2 -2
- data/spec/unit/adapters/active_record/abstract_object_spec.rb +8 -8
- data/spec/unit/adapters/active_record_spec.rb +6 -6
- data/spec/unit/adapters/mongoid/abstract_object_spec.rb +1 -1
- data/spec/unit/adapters/mongoid_spec.rb +12 -12
- data/spec/unit/config/actions/base_spec.rb +2 -2
- data/spec/unit/config/actions_spec.rb +16 -16
- data/spec/unit/config/fields/base_spec.rb +61 -49
- data/spec/unit/config/fields/date_spec.rb +4 -4
- data/spec/unit/config/fields/datetime_spec.rb +4 -4
- data/spec/unit/config/fields/file_upload_spec.rb +21 -0
- data/spec/unit/config/fields/time_spec.rb +3 -3
- data/spec/unit/config/fields/timestamp_spec.rb +1 -1
- data/spec/unit/config/model_spec.rb +10 -10
- data/spec/unit/config/sections_spec.rb +4 -4
- data/spec/unit/config_spec.rb +9 -9
- metadata +17 -218
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe RailsAdmin do
|
|
4
4
|
|
|
5
5
|
subject { page }
|
|
6
6
|
|
|
7
7
|
describe "authentication" do
|
|
8
|
-
it "
|
|
8
|
+
it "is disableable" do
|
|
9
9
|
logout
|
|
10
10
|
RailsAdmin.config do |config|
|
|
11
11
|
config.authenticate_with {}
|
|
@@ -18,7 +18,7 @@ describe "RailsAdmin" do
|
|
|
18
18
|
# root key from en to their own locale (as people tend to use the English
|
|
19
19
|
# file as template for a new translation).
|
|
20
20
|
describe "localization" do
|
|
21
|
-
it "
|
|
21
|
+
it "defaults to English" do
|
|
22
22
|
visit dashboard_path
|
|
23
23
|
|
|
24
24
|
should have_content("Site administration")
|
|
@@ -31,16 +31,16 @@ describe "RailsAdmin" do
|
|
|
31
31
|
|
|
32
32
|
# Note: the [href^="/asset... syntax matches the start of a value. The reason
|
|
33
33
|
# we just do that is to avoid being confused by rails' asset_ids.
|
|
34
|
-
it "
|
|
34
|
+
it "loads stylesheets in header" do
|
|
35
35
|
should have_selector('head link[href^="/assets/rails_admin/rails_admin.css"]')
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
it "
|
|
38
|
+
it "loads javascript files in body" do
|
|
39
39
|
should have_selector('head script[src^="/assets/rails_admin/rails_admin.js"]')
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
describe
|
|
43
|
+
describe "hidden fields with default values" do
|
|
44
44
|
|
|
45
45
|
before (:each) do
|
|
46
46
|
RailsAdmin.config Player do
|
|
@@ -55,24 +55,24 @@ describe "RailsAdmin" do
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
it "
|
|
58
|
+
it "shows up with default value, hidden" do
|
|
59
59
|
visit new_path(:model_name => "player")
|
|
60
60
|
should have_selector("#player_name[type=hidden][value='username@example.com']")
|
|
61
61
|
should_not have_selector("#player_name[type=hidden][value='toto@example.com']")
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
it "
|
|
64
|
+
it "does not show label" do
|
|
65
65
|
should_not have_selector("label", :text => "Name")
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
it "
|
|
68
|
+
it "does not show help block" do
|
|
69
69
|
should_not have_xpath("id('player_name')/../p[@class='help-block']")
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
-
describe
|
|
73
|
+
describe "_current_user" do # https://github.com/sferik/rails_admin/issues/549
|
|
74
74
|
|
|
75
|
-
it
|
|
75
|
+
it "is accessible from the list view" do
|
|
76
76
|
RailsAdmin.config Player do
|
|
77
77
|
list do
|
|
78
78
|
field :name do
|
|
@@ -101,20 +101,20 @@ describe "RailsAdmin" do
|
|
|
101
101
|
@comment = FactoryGirl.create :comment, :commentable => @team
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
-
it "
|
|
104
|
+
it "works like belongs to associations in the list view" do
|
|
105
105
|
visit index_path(:model_name => "comment")
|
|
106
106
|
|
|
107
107
|
should have_content(@team.name)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
it "
|
|
110
|
+
it "is editable" do
|
|
111
111
|
visit edit_path(:model_name => "comment", :id => @comment.id)
|
|
112
112
|
|
|
113
113
|
should have_selector("select#comment_commentable_type")
|
|
114
114
|
should have_selector("select#comment_commentable_id")
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
it "
|
|
117
|
+
it "is visible in the owning end" do
|
|
118
118
|
visit edit_path(:model_name => "team", :id => @team.id)
|
|
119
119
|
|
|
120
120
|
should have_selector("select#team_comment_ids")
|
|
@@ -122,18 +122,18 @@ describe "RailsAdmin" do
|
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
describe "secondary navigation" do
|
|
125
|
-
it "
|
|
125
|
+
it "has Gravatar image" do
|
|
126
126
|
visit dashboard_path
|
|
127
127
|
should have_selector("ul.nav.pull-right li img")
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
it "
|
|
130
|
+
it "does not show Gravatar when user doesn't have email method" do
|
|
131
131
|
User.any_instance.stub(:respond_to?).with(:email).and_return(false)
|
|
132
132
|
visit dashboard_path
|
|
133
133
|
should_not have_selector("ul.nav.pull-right li img")
|
|
134
134
|
end
|
|
135
135
|
|
|
136
|
-
it "
|
|
136
|
+
it "does not cause error when email is nil" do
|
|
137
137
|
User.any_instance.stub(:email).and_return(nil)
|
|
138
138
|
visit dashboard_path
|
|
139
139
|
should have_selector("body.rails_admin")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe
|
|
3
|
+
describe "table relations" do
|
|
4
4
|
|
|
5
5
|
before(:each) do
|
|
6
6
|
class RelTest < Tableless
|
|
@@ -15,20 +15,20 @@ describe 'table relations' do
|
|
|
15
15
|
@fields = RailsAdmin.config(RelTest).create.fields
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
describe
|
|
19
|
-
it
|
|
18
|
+
describe "column with nullable fk and no model validations" do
|
|
19
|
+
it "is optional" do
|
|
20
20
|
expect(@fields.find{ |f| f.name == :league }.required?).to be_false
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
describe
|
|
25
|
-
it
|
|
24
|
+
describe "column with non-nullable fk and no model validations" do
|
|
25
|
+
it "is not required" do
|
|
26
26
|
expect(@fields.find{ |f| f.name == :division }.required?).to be_false
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
describe
|
|
31
|
-
it
|
|
30
|
+
describe "column with nullable fk and a numericality model validation" do
|
|
31
|
+
it "is required" do
|
|
32
32
|
expect(@fields.find{ |f| f.name == :player }.required?).to be_true
|
|
33
33
|
end
|
|
34
34
|
end
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe RailsAdmin::AbstractModel do
|
|
4
|
-
describe
|
|
4
|
+
describe "filters" do
|
|
5
5
|
before do
|
|
6
6
|
@abstract_model = RailsAdmin::AbstractModel.new('FieldTest')
|
|
7
7
|
end
|
|
8
|
+
|
|
9
|
+
context "ActiveModel::ForbiddenAttributesProtection" do
|
|
10
|
+
it "is present" do
|
|
11
|
+
@abstract_model.model.ancestors.map(&:to_s).include?('ActiveModel::ForbiddenAttributesProtection')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
8
14
|
|
|
9
|
-
context
|
|
10
|
-
it
|
|
15
|
+
context "on dates" do
|
|
16
|
+
it "lists elements within outbound limits" do
|
|
11
17
|
date_format = I18n.t("admin.misc.filter_date_format", :default => I18n.t("admin.misc.filter_date_format", :locale => :en)).gsub('dd', '%d').gsub('mm', '%m').gsub('yy', '%Y')
|
|
12
18
|
|
|
13
19
|
FactoryGirl.create(:field_test, :date_field => Date.strptime("01/01/2012", date_format))
|
|
@@ -23,8 +29,8 @@ describe RailsAdmin::AbstractModel do
|
|
|
23
29
|
end
|
|
24
30
|
end
|
|
25
31
|
|
|
26
|
-
context
|
|
27
|
-
it
|
|
32
|
+
context "on datetimes" do
|
|
33
|
+
it "lists elements within outbound limits" do
|
|
28
34
|
FactoryGirl.create(:field_test, :datetime_field => Time.local(2012, 1, 1, 23, 59, 59))
|
|
29
35
|
FactoryGirl.create(:field_test, :datetime_field => Time.local(2012, 1, 2, 0, 0, 0))
|
|
30
36
|
FactoryGirl.create(:field_test, :datetime_field => Time.local(2012, 1, 3, 23, 59, 59))
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require File.expand_path('../../../config/initializers/active_record_extensions', __FILE__)
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
describe
|
|
4
|
+
describe "ActiveRecord::Base", :active_record => true do
|
|
5
|
+
describe "#safe_send" do
|
|
6
6
|
it "only calls #read_attribute once" do
|
|
7
7
|
@player = Player.new
|
|
8
8
|
@player.number = 23
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe "AbstractObject", :active_record => true do
|
|
3
|
+
describe "RailsAdmin::Adapters::ActiveRecord::AbstractObject", :active_record => true do
|
|
4
4
|
describe "proxy" do
|
|
5
5
|
let(:object) { mock("object") }
|
|
6
6
|
let(:abstract_object) { RailsAdmin::Adapters::ActiveRecord::AbstractObject.new(object) }
|
|
7
7
|
|
|
8
|
-
it "
|
|
8
|
+
it "acts like a proxy" do
|
|
9
9
|
object.should_receive(:method_call)
|
|
10
10
|
abstract_object.method_call
|
|
11
11
|
end
|
|
@@ -24,7 +24,7 @@ describe "AbstractObject", :active_record => true do
|
|
|
24
24
|
object.set_attributes({ :name => name, :number => number, :position => position, :suspended => suspended, :team_id => nil })
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
-
it "
|
|
27
|
+
it "creates a Player with given attributes" do
|
|
28
28
|
expect(object.save).to be_true
|
|
29
29
|
|
|
30
30
|
player.reload
|
|
@@ -45,7 +45,7 @@ describe "AbstractObject", :active_record => true do
|
|
|
45
45
|
object.set_attributes({ :name => name, :number => number, :position => position, :suspended => suspended, :team_id => nil, :draft_id => draft.id })
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
it "
|
|
48
|
+
it "creates a Player with given attributes" do
|
|
49
49
|
expect(object.save).to be_true
|
|
50
50
|
|
|
51
51
|
player.reload
|
|
@@ -69,7 +69,7 @@ describe "AbstractObject", :active_record => true do
|
|
|
69
69
|
object.set_attributes({ :name => name, :division_ids => divisions.map(&:id) })
|
|
70
70
|
end
|
|
71
71
|
|
|
72
|
-
it "
|
|
72
|
+
it "creates a League with given attributes and associations" do
|
|
73
73
|
expect(object.save).to be_true
|
|
74
74
|
league.reload
|
|
75
75
|
expect(league.name).to eq(name)
|
|
@@ -94,7 +94,7 @@ describe "AbstractObject", :active_record => true do
|
|
|
94
94
|
object.save
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
it "
|
|
97
|
+
it "updates a record and associations" do
|
|
98
98
|
object.reload
|
|
99
99
|
expect(object.number).to eq(new_number)
|
|
100
100
|
expect(object.name).to eq(name)
|
|
@@ -113,13 +113,13 @@ describe "AbstractObject", :active_record => true do
|
|
|
113
113
|
object.destroy
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
-
it "
|
|
116
|
+
it "deletes the record" do
|
|
117
117
|
expect(Player.exists?(player.id)).to be_false
|
|
118
118
|
end
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
describe "object_label_method" do
|
|
122
|
-
it
|
|
122
|
+
it "is configurable" do
|
|
123
123
|
RailsAdmin.config League do
|
|
124
124
|
object_label_method { :custom_name }
|
|
125
125
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'timecop'
|
|
3
3
|
|
|
4
|
-
describe
|
|
4
|
+
describe "RailsAdmin::Adapters::ActiveRecord", :active_record => true do
|
|
5
5
|
before do
|
|
6
6
|
@like = ::ActiveRecord::Base.configurations[Rails.env]['adapter'] == "postgresql" ? 'ILIKE' : 'LIKE'
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
describe
|
|
9
|
+
describe "#associations" do
|
|
10
10
|
before :all do
|
|
11
11
|
RailsAdmin::AbstractModel.reset_polymorphic_parents
|
|
12
12
|
|
|
@@ -49,11 +49,11 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
|
49
49
|
RailsAdmin::AbstractModel.reset_polymorphic_parents
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
it
|
|
52
|
+
it "lists associations" do
|
|
53
53
|
expect(@post.associations.map{|a|a[:name].to_s}).to match_array ['a_r_blog', 'a_r_categories', 'a_r_comments']
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
it
|
|
56
|
+
it "list associations types in supported [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]" do
|
|
57
57
|
expect((@post.associations + @blog.associations + @user.associations).map{|a|a[:type]}.uniq.map(&:to_s)).to match_array ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -339,14 +339,14 @@ describe 'RailsAdmin::Adapters::ActiveRecord', :active_record => true do
|
|
|
339
339
|
end
|
|
340
340
|
|
|
341
341
|
|
|
342
|
-
it
|
|
342
|
+
it "supports date type query" do
|
|
343
343
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } })).to eq(["((field_tests.date_field BETWEEN ? AND ?))", Date.new(2012,1,2), Date.new(2012,1,3)])
|
|
344
344
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq(["((field_tests.date_field >= ?))", Date.new(2012,1,3)])
|
|
345
345
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq(["((field_tests.date_field <= ?))", Date.new(2012,1,2)])
|
|
346
346
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq(["((field_tests.date_field BETWEEN ? AND ?))", Date.new(2012,1,2), Date.new(2012,1,2)])
|
|
347
347
|
end
|
|
348
348
|
|
|
349
|
-
it
|
|
349
|
+
it "supports datetime type query" do
|
|
350
350
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } )).to eq(["((field_tests.datetime_field BETWEEN ? AND ?))", Time.local(2012,1,2), Time.local(2012,1,3).end_of_day])
|
|
351
351
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq(["((field_tests.datetime_field >= ?))", Time.local(2012,1,3)])
|
|
352
352
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq(["((field_tests.datetime_field <= ?))", Time.local(2012,1,2).end_of_day])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'rails_admin/adapters/mongoid/abstract_object'
|
|
3
3
|
|
|
4
|
-
describe "Mongoid::AbstractObject", :mongoid => true do
|
|
4
|
+
describe "RailsAdmin::Adapters::Mongoid::AbstractObject", :mongoid => true do
|
|
5
5
|
before(:each) do
|
|
6
6
|
@players = FactoryGirl.create_list :player, 3
|
|
7
7
|
@team = RailsAdmin::Adapters::Mongoid::AbstractObject.new FactoryGirl.create :team
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'timecop'
|
|
3
3
|
|
|
4
|
-
describe
|
|
5
|
-
describe
|
|
4
|
+
describe "RailsAdmin::Adapters::Mongoid", :mongoid => true do
|
|
5
|
+
describe "#associations" do
|
|
6
6
|
before :all do
|
|
7
7
|
RailsAdmin::AbstractModel.reset_polymorphic_parents
|
|
8
8
|
|
|
@@ -67,11 +67,11 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
67
67
|
RailsAdmin::AbstractModel.reset_polymorphic_parents
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
-
it
|
|
70
|
+
it "lists associations" do
|
|
71
71
|
expect(@post.associations.map{|a| a[:name]}).to match_array [:mongo_blog, :mongo_categories, :mongo_comments, :mongo_note]
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
it
|
|
74
|
+
it "reads correct and know types in [:belongs_to, :has_and_belongs_to_many, :has_many, :has_one]" do
|
|
75
75
|
expect((@post.associations + @blog.associations + @user.associations).map{|a|a[:type].to_s}.uniq).to match_array ['belongs_to', 'has_and_belongs_to_many', 'has_many', 'has_one']
|
|
76
76
|
end
|
|
77
77
|
|
|
@@ -114,7 +114,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
114
114
|
expect(@post.properties.find{|f| f[:name] == :mongo_blog_id}[:type]).to eq(:bson_object_id)
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
it "
|
|
117
|
+
it "does not confuse foreign_key column which belongs to associated model" do
|
|
118
118
|
expect(@blog.properties.find{|f| f[:name] == :mongo_blog_id}[:type]).to eq(:string)
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -215,7 +215,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
215
215
|
expect(param[:model_proc].call).to eq(MongoNote)
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
-
it "
|
|
218
|
+
it "raises error when embeds_* is used without accepts_nested_attributes_for" do
|
|
219
219
|
class MongoEmbedsOne
|
|
220
220
|
include Mongoid::Document
|
|
221
221
|
embeds_one :mongo_embedded
|
|
@@ -240,7 +240,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
240
240
|
)
|
|
241
241
|
end
|
|
242
242
|
|
|
243
|
-
it "
|
|
243
|
+
it "works with inherited embeds_many model" do
|
|
244
244
|
class MongoEmbedsParent
|
|
245
245
|
include Mongoid::Document
|
|
246
246
|
embeds_many :mongo_embeddeds
|
|
@@ -407,7 +407,7 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
407
407
|
expect(RailsAdmin::AbstractModel.new('LengthValiated').send(:length_validation_lookup, :text)).to eq(50)
|
|
408
408
|
end
|
|
409
409
|
|
|
410
|
-
it "
|
|
410
|
+
it "does not cause problem with custom validators" do
|
|
411
411
|
class MyCustomValidator < ActiveModel::Validator
|
|
412
412
|
def validate(r); end
|
|
413
413
|
end
|
|
@@ -693,14 +693,14 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
693
693
|
expect(@abstract_model.send(:build_statement, :field, :string, "foo", "is")).to eq({:field => 'foo'})
|
|
694
694
|
end
|
|
695
695
|
|
|
696
|
-
it
|
|
696
|
+
it "supports date type query" do
|
|
697
697
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } })).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,2), "$lte" => Date.new(2012,1,3)}}]})
|
|
698
698
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,3)}}]})
|
|
699
699
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq({"$and" => [{"date_field" => {"$lte" => Date.new(2012,1,2)}}]})
|
|
700
700
|
expect(@abstract_model.send(:filter_conditions, { "date_field" => { "1" => { :v => ["01/02/2012"], :o => 'default' } } } )).to eq({"$and" => [{"date_field" => {"$gte" => Date.new(2012,1,2), "$lte" => Date.new(2012,1,2)}}]})
|
|
701
701
|
end
|
|
702
702
|
|
|
703
|
-
it
|
|
703
|
+
it "supports datetime type query" do
|
|
704
704
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/02/2012", "01/03/2012"], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$gte" => Time.local(2012,1,2), "$lte" => Time.local(2012,1,3).end_of_day}}]})
|
|
705
705
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "01/03/2012", ""], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$gte" => Time.local(2012,1,3)}}]})
|
|
706
706
|
expect(@abstract_model.send(:filter_conditions, { "datetime_field" => { "1" => { :v => ["", "", "01/02/2012"], :o => 'between' } } } )).to eq({"$and" => [{"datetime_field" => {"$lte" => Time.local(2012,1,2).end_of_day}}]})
|
|
@@ -733,13 +733,13 @@ describe 'RailsAdmin::Adapters::Mongoid', :mongoid => true do
|
|
|
733
733
|
end
|
|
734
734
|
|
|
735
735
|
it "accepts array value" do
|
|
736
|
-
params = {:array_field => '[1, 3]'}
|
|
736
|
+
params = HashWithIndifferentAccess.new({:array_field => '[1, 3]'})
|
|
737
737
|
@controller.send(:sanitize_params_for!, 'create', @abstract_model.config, params)
|
|
738
738
|
expect(params[:array_field]).to eq([1, 3])
|
|
739
739
|
end
|
|
740
740
|
|
|
741
741
|
it "accepts hash value" do
|
|
742
|
-
params = {:hash_field => '{a: 1, b: 3}'}
|
|
742
|
+
params = HashWithIndifferentAccess.new({:hash_field => '{a: 1, b: 3}'})
|
|
743
743
|
@controller.send(:sanitize_params_for!, 'create', @abstract_model.config, params)
|
|
744
744
|
expect(params[:hash_field]).to eq({"a" => 1, "b" => 3})
|
|
745
745
|
end
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
describe RailsAdmin::Config::Actions::Base do
|
|
4
4
|
|
|
5
5
|
describe "#visible?" do
|
|
6
|
-
it
|
|
6
|
+
it "excludes models not referenced in the only array" do
|
|
7
7
|
RailsAdmin.config do |config|
|
|
8
8
|
config.actions do
|
|
9
9
|
index do
|
|
@@ -16,7 +16,7 @@ describe RailsAdmin::Config::Actions::Base do
|
|
|
16
16
|
expect(RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Cms::BasicPage)})).to be_visible
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
it
|
|
19
|
+
it "excludes models referenced in the except array" do
|
|
20
20
|
RailsAdmin.config do |config|
|
|
21
21
|
config.actions do
|
|
22
22
|
index do
|
|
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
|
3
3
|
describe RailsAdmin::Config::Actions do
|
|
4
4
|
|
|
5
5
|
describe "default" do
|
|
6
|
-
it
|
|
6
|
+
it "is as before" do
|
|
7
7
|
expect(RailsAdmin::Config::Actions.all.map(&:key)).to eq([:dashboard, :index, :show, :new, :edit, :export, :delete, :bulk_delete, :history_show, :history_index, :show_in_app])
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
describe
|
|
12
|
-
it
|
|
11
|
+
describe "find" do
|
|
12
|
+
it "finds by custom key" do
|
|
13
13
|
RailsAdmin.config do |config|
|
|
14
14
|
config.actions do
|
|
15
15
|
dashboard do
|
|
@@ -27,11 +27,11 @@ describe RailsAdmin::Config::Actions do
|
|
|
27
27
|
expect(RailsAdmin::Config::Actions.find(:show)).to be_a(RailsAdmin::Config::Actions::Show)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
it
|
|
30
|
+
it "returns nil when no action is found by the custom key" do
|
|
31
31
|
expect(RailsAdmin::Config::Actions.find(:non_existent_action_key)).to be_nil
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
-
it
|
|
34
|
+
it "returns visible action passing binding if controller binding is given, and pass action visible or not if no" do
|
|
35
35
|
RailsAdmin.config do |config|
|
|
36
36
|
config.actions do
|
|
37
37
|
root :custom_root do
|
|
@@ -46,7 +46,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
46
46
|
expect(RailsAdmin::Config::Actions.find(:custom_root, {:controller => "controller"})).to be_a(RailsAdmin::Config::Actions::Base)
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
it
|
|
49
|
+
it "checks bindings[:abstract_model] visibility while checking action\'s visibility" do
|
|
50
50
|
RailsAdmin.config Team do
|
|
51
51
|
hide
|
|
52
52
|
end
|
|
@@ -55,7 +55,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
55
55
|
expect(RailsAdmin::Config::Actions.find(:index, {:controller => double(:authorized? => true), :abstract_model => RailsAdmin::AbstractModel.new(Team)})).to be_nil
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
-
it
|
|
58
|
+
it "checks bindings[:abstract_model] presence while checking action\'s visibility" do
|
|
59
59
|
RailsAdmin.config do |config|
|
|
60
60
|
config.excluded_models << Team
|
|
61
61
|
end
|
|
@@ -64,8 +64,8 @@ describe RailsAdmin::Config::Actions do
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
describe
|
|
68
|
-
it
|
|
67
|
+
describe "all" do
|
|
68
|
+
it "returns all defined actions" do
|
|
69
69
|
RailsAdmin.config do |config|
|
|
70
70
|
config.actions do
|
|
71
71
|
dashboard
|
|
@@ -76,7 +76,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
76
76
|
expect(RailsAdmin::Config::Actions.all.map(&:key)).to eq([:dashboard, :index])
|
|
77
77
|
end
|
|
78
78
|
|
|
79
|
-
it
|
|
79
|
+
it "restricts by scope" do
|
|
80
80
|
RailsAdmin.config do |config|
|
|
81
81
|
config.actions do
|
|
82
82
|
root :custom_root
|
|
@@ -89,7 +89,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
89
89
|
expect(RailsAdmin::Config::Actions.all(:member).map(&:key)).to eq([:custom_member])
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
it
|
|
92
|
+
it "returns all visible actions passing binding if controller binding is given, and pass all actions if no" do
|
|
93
93
|
RailsAdmin.config do |config|
|
|
94
94
|
config.actions do
|
|
95
95
|
root :custom_root do
|
|
@@ -106,7 +106,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
describe "customized through DSL" do
|
|
109
|
-
it
|
|
109
|
+
it "adds the one asked" do
|
|
110
110
|
RailsAdmin.config do |config|
|
|
111
111
|
config.actions do
|
|
112
112
|
dashboard
|
|
@@ -118,7 +118,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
118
118
|
expect(RailsAdmin::Config::Actions.all.map(&:key)).to eq([:dashboard, :index, :show])
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
-
it
|
|
121
|
+
it "allows to customize the custom_key when customizing an existing action" do
|
|
122
122
|
RailsAdmin.config do |config|
|
|
123
123
|
config.actions do
|
|
124
124
|
dashboard do
|
|
@@ -130,7 +130,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
130
130
|
expect(RailsAdmin::Config::Actions.all.map(&:key)).to eq([:dashboard])
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
it
|
|
133
|
+
it "allows to change the key and the custom_key when subclassing an existing action" do
|
|
134
134
|
RailsAdmin.config do |config|
|
|
135
135
|
config.actions do
|
|
136
136
|
root :my_dashboard_key, :dashboard do
|
|
@@ -143,7 +143,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
143
143
|
expect(RailsAdmin::Config::Actions.all.map(&:class)).to eq([RailsAdmin::Config::Actions::Dashboard])
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
-
it
|
|
146
|
+
it "does not add the same custom_key twice" do
|
|
147
147
|
expect do
|
|
148
148
|
RailsAdmin.config do |config|
|
|
149
149
|
config.actions do
|
|
@@ -163,7 +163,7 @@ describe RailsAdmin::Config::Actions do
|
|
|
163
163
|
end.to raise_error("Action index already exist. Please change its custom key")
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
it
|
|
166
|
+
it "adds the same key with different custom key" do
|
|
167
167
|
RailsAdmin.config do |config|
|
|
168
168
|
config.actions do
|
|
169
169
|
dashboard
|