rails_admin 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails_admin might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/Gemfile +2 -2
  2. data/README.md +13 -6
  3. data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
  4. data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
  5. data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
  6. data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
  7. data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  8. data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  9. data/app/assets/images/rails_admin/bullet_white.png +0 -0
  10. data/app/assets/images/rails_admin/calendar.png +0 -0
  11. data/app/assets/images/rails_admin/clock.png +0 -0
  12. data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
  13. data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
  14. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
  15. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
  16. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
  17. data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
  18. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
  19. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
  20. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
  21. data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
  22. data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
  23. data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
  24. data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
  25. data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
  26. data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
  27. data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
  28. data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
  29. data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
  30. data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
  31. data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
  32. data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
  33. data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
  34. data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
  35. data/app/assets/images/rails_admin/logo.png +0 -0
  36. data/app/assets/images/rails_admin/magnifier.png +0 -0
  37. data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
  38. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
  39. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
  40. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
  41. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
  42. data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
  43. data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
  44. data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
  45. data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
  46. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  47. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  48. data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +1 -0
  49. data/app/controllers/rails_admin/main_controller.rb +1 -1
  50. data/app/helpers/rails_admin/application_helper.rb +3 -2
  51. data/app/views/rails_admin/main/index.html.haml +1 -1
  52. data/lib/generators/rails_admin/install_generator.rb +1 -1
  53. data/lib/rails_admin/abstract_model.rb +4 -0
  54. data/lib/rails_admin/adapters/active_record.rb +4 -0
  55. data/lib/rails_admin/adapters/mongoid.rb +6 -0
  56. data/lib/rails_admin/adapters/mongoid/abstract_object.rb +3 -3
  57. data/lib/rails_admin/config.rb +9 -12
  58. data/lib/rails_admin/config/actions/base.rb +4 -3
  59. data/lib/rails_admin/config/fields/association.rb +1 -1
  60. data/lib/rails_admin/config/fields/base.rb +1 -1
  61. data/lib/rails_admin/config/fields/factories/association.rb +1 -1
  62. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +1 -1
  63. data/lib/rails_admin/config/fields/types/boolean.rb +2 -2
  64. data/lib/rails_admin/config/fields/types/datetime.rb +1 -1
  65. data/lib/rails_admin/config/has_fields.rb +3 -2
  66. data/lib/rails_admin/config/lazy_model.rb +21 -0
  67. data/lib/rails_admin/extensions/history/history.rb +5 -5
  68. data/lib/rails_admin/support/csv_converter.rb +2 -6
  69. data/lib/rails_admin/version.rb +1 -1
  70. data/spec/controllers/{application_controller_spec.rb → rails_admin/application_controller_spec.rb} +0 -0
  71. data/spec/controllers/{main_controller_spec.rb → rails_admin/main_controller_spec.rb} +36 -4
  72. data/spec/dummy_app/Gemfile +2 -2
  73. data/spec/dummy_app/app/active_record/comment.rb +1 -1
  74. data/spec/dummy_app/app/active_record/team.rb +1 -1
  75. data/spec/dummy_app/app/mongoid/field_test.rb +2 -1
  76. data/spec/dummy_app/app/mongoid/team.rb +1 -1
  77. data/spec/dummy_app/db/seeds.rb +4 -4
  78. data/spec/dummy_app/db/test.sqlite3 +0 -0
  79. data/spec/dummy_app/log/test.log +156160 -0
  80. data/spec/helpers/rails_admin/application_helper_spec.rb +353 -0
  81. data/spec/helpers/{form_builder_spec.rb → rails_admin/form_builder_spec.rb} +0 -0
  82. data/spec/integration/authorization/cancan_spec.rb +13 -13
  83. data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +2 -2
  84. data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +13 -2
  85. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +8 -9
  86. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +1 -1
  87. data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +4 -4
  88. data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +2 -2
  89. data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +2 -2
  90. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +51 -21
  91. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +15 -15
  92. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +13 -14
  93. data/spec/integration/config/list/rails_admin_config_list_spec.rb +7 -6
  94. data/spec/integration/config/show/rails_admin_config_show_spec.rb +1 -1
  95. data/spec/integration/rails_admin_spec.rb +2 -0
  96. data/spec/{unit → rails_admin}/abstract_model_spec.rb +7 -0
  97. data/spec/{unit → rails_admin}/active_record_extension_spec.rb +0 -0
  98. data/spec/{unit → rails_admin}/adapters/active_record/abstract_object_spec.rb +0 -0
  99. data/spec/{unit → rails_admin}/adapters/active_record_spec.rb +0 -0
  100. data/spec/{unit → rails_admin}/adapters/mongoid/abstract_object_spec.rb +0 -0
  101. data/spec/{unit → rails_admin}/adapters/mongoid_spec.rb +7 -1
  102. data/spec/{unit → rails_admin}/config/actions/base_spec.rb +0 -0
  103. data/spec/{unit → rails_admin}/config/actions_spec.rb +0 -0
  104. data/spec/{unit → rails_admin}/config/fields/base_spec.rb +0 -0
  105. data/spec/{unit → rails_admin}/config/fields/date_spec.rb +0 -0
  106. data/spec/{unit → rails_admin}/config/fields/datetime_spec.rb +0 -0
  107. data/spec/{unit → rails_admin}/config/fields/file_upload_spec.rb +0 -0
  108. data/spec/{unit → rails_admin}/config/fields/time_spec.rb +0 -0
  109. data/spec/{unit → rails_admin}/config/fields/timestamp_spec.rb +0 -0
  110. data/spec/rails_admin/config/fields/types/datetime_spec.rb +18 -0
  111. data/spec/{unit → rails_admin}/config/fields_spec.rb +0 -0
  112. data/spec/rails_admin/config/has_fields_spec.rb +30 -0
  113. data/spec/rails_admin/config/lazy_model_spec.rb +29 -0
  114. data/spec/{unit → rails_admin}/config/model_spec.rb +0 -0
  115. data/spec/{unit → rails_admin}/config/sections_spec.rb +0 -0
  116. data/spec/{unit → rails_admin}/config_spec.rb +0 -0
  117. data/spec/{unit → rails_admin}/support/csv_converter_spec.rb +0 -0
  118. data/spec/spec_helper.rb +2 -0
  119. metadata +65 -60
  120. data/spec/helpers/application_helper_spec.rb +0 -328
@@ -9,7 +9,7 @@ describe "RailsAdmin Basic Create" do
9
9
  fill_in "player[name]", :with => "Jackie Robinson"
10
10
  fill_in "player[number]", :with => "42"
11
11
  fill_in "player[position]", :with => "Second baseman"
12
- click_button "Save"
12
+ click_button "Save" # first(:button, "Save").click
13
13
  @player = RailsAdmin::AbstractModel.new("Player").first
14
14
  end
15
15
 
@@ -62,7 +62,7 @@ describe "RailsAdmin Basic Create" do
62
62
  before(:each) do
63
63
  @draft = FactoryGirl.create :draft
64
64
 
65
- page.driver.post new_path(:model_name => "player", :player => {:name => "Jackie Robinson", :number => 42, :position => 'Second baseman', :draft_id => @draft.id})
65
+ post new_path(:model_name => "player", :player => {:name => "Jackie Robinson", :number => 42, :position => 'Second baseman', :draft_id => @draft.id})
66
66
 
67
67
  @player = RailsAdmin::AbstractModel.new("Player").all.last # first is created by FactoryGirl
68
68
  end
@@ -76,7 +76,7 @@ describe "RailsAdmin Basic Create" do
76
76
  describe "create with has-many association" do
77
77
  before(:each) do
78
78
  @divisions = 3.times.map { Division.create!(:name => "div #{Time.now.to_f}", :league => League.create!(:name => "league #{Time.now.to_f}")) }
79
- page.driver.post new_path(:model_name => "league", :league => {:name => "National League", :division_ids =>[@divisions[0].id]})
79
+ post new_path(:model_name => "league", :league => {:name => "National League", :division_ids =>[@divisions[0].id]})
80
80
  @league = RailsAdmin::AbstractModel.new("League").all.last
81
81
  end
82
82
 
@@ -91,7 +91,7 @@ describe "RailsAdmin Basic Create" do
91
91
  describe "create with has-and-belongs-to-many association" do
92
92
  before(:each) do
93
93
  @teams = 3.times.map { FactoryGirl.create :team }
94
- page.driver.post new_path(:model_name => "fan", :fan => {:name => "John Doe", :team_ids => [@teams[0].id] })
94
+ post new_path(:model_name => "fan", :fan => {:name => "John Doe", :team_ids => [@teams[0].id] })
95
95
  @fan = RailsAdmin::AbstractModel.new("Fan").first
96
96
  end
97
97
 
@@ -108,22 +108,21 @@ describe "RailsAdmin Basic Create" do
108
108
  @team = FactoryGirl.create :team
109
109
  @player = FactoryGirl.create :player, :team => @team
110
110
 
111
- page.driver.post new_path(:model_name => "player", :player => {:name => @player.name, :number => @player.number.to_s, :position => @player.position, :team_id => @team.id})
111
+ post new_path(:model_name => "player", :player => {:name => @player.name, :number => @player.number.to_s, :position => @player.position, :team_id => @team.id})
112
112
  end
113
113
 
114
114
  it "shows an error message" do
115
- should have_content("There is already a player with that number on this team")
115
+ expect(response.body).to include("There is already a player with that number on this team")
116
116
  end
117
117
  end
118
118
 
119
119
  describe "create with invalid object" do
120
120
  before(:each) do
121
- page.driver.post(new_path(:model_name => "player", :id => 1), :params => {:player => {}})
121
+ post new_path(:model_name => "player", :player => {:id => 1})
122
122
  end
123
123
 
124
124
  it "shows an error message" do
125
- should have_content("Player failed to be created")
126
- should have_selector "form", :action => "/admin/players"
125
+ expect(response.body).to include("Player failed to be created")
127
126
  end
128
127
  end
129
128
 
@@ -10,7 +10,7 @@ describe "RailsAdmin Namespaced Model Create" do
10
10
  fill_in "cms_basic_page[title]", :with => "Hello"
11
11
  fill_in "cms_basic_page[content]", :with => "World"
12
12
  expect {
13
- click_button "Save"
13
+ click_button "Save" # first(:button, "Save").click
14
14
  }.to change(Cms::BasicPage, :count).by(1)
15
15
  end
16
16
  end
@@ -53,11 +53,11 @@ describe "RailsAdmin Basic Destroy" do
53
53
 
54
54
  describe "destroy with missing object" do
55
55
  before(:each) do
56
- page.driver.delete(delete_path(:model_name => "player", :id => 1))
56
+ delete delete_path(:model_name => "player", :id => 1)
57
57
  end
58
58
 
59
59
  it "raises NotFound" do
60
- expect(page.driver.status_code).to eq(404)
60
+ expect(response.code).to eq("404")
61
61
  end
62
62
  end
63
63
 
@@ -65,7 +65,7 @@ describe "RailsAdmin Basic Destroy" do
65
65
  it "redirects to the index instead of trying to show the deleted object" do
66
66
  @player = FactoryGirl.create :player
67
67
  visit show_path(:model_name => 'player', :id => @player.id)
68
- visit delete_path(:model_name => "player", :id => @player.id)
68
+ click_link "Delete"
69
69
  click_button "Yes, I'm sure"
70
70
 
71
71
  expect(URI.parse(page.current_url).path).to eq(index_path(:model_name => 'player'))
@@ -75,7 +75,7 @@ describe "RailsAdmin Basic Destroy" do
75
75
  Player.any_instance.stub(:destroy_hook).and_return false
76
76
  @player = FactoryGirl.create :player
77
77
  visit show_path(:model_name => 'player', :id => @player.id)
78
- visit delete_path(:model_name => "player", :id => @player.id)
78
+ click_link "Delete"
79
79
  click_button "Yes, I'm sure"
80
80
 
81
81
  expect(URI.parse(page.current_url).path).to eq(show_path(:model_name => 'player', :id => @player.id))
@@ -30,13 +30,13 @@ describe "RailsAdmin Basic Edit" do
30
30
  it "adds a related id to the belongs_to create team link" do
31
31
  @player = FactoryGirl.create :player
32
32
  visit edit_path(:model_name => "player", :id => @player.id)
33
- should have_selector("a", :href => 'admin/teams/new?associations[players]=' + @player.id.to_s)
33
+ should have_selector("a[data-link='/admin/team/new?associations%5Bplayers%5D=#{@player.id.to_s}&modal=true']")
34
34
  end
35
35
 
36
36
  it "adds a related id to the has_many create team link" do
37
37
  @team = FactoryGirl.create :team
38
38
  visit edit_path(:model_name => "team", :id => @team.id)
39
- should have_selector("a", :href => 'admin/players/new?associations[team]=' + @team.id.to_s)
39
+ should have_selector("a[data-link='/admin/player/new?associations%5Bteam%5D=#{@team.id.to_s}&modal=true']")
40
40
  end
41
41
  end
42
42
 
@@ -46,7 +46,7 @@ describe "RailsAdmin Export" do
46
46
  should have_content 'Select fields to export'
47
47
  select "<comma> ','", :from => "csv_options_generator_col_sep"
48
48
  click_button 'Export to csv'
49
- csv = CSV.parse find('body').text
49
+ csv = CSV.parse page.driver.response.body.force_encoding("utf-8") # comes through as us-ascii on some platforms
50
50
  expect(csv[0]).to match_array ["Id", "Created at", "Updated at", "Deleted at", "Name", "Position",
51
51
  "Number", "Retired", "Injured", "Born on", "Notes", "Suspended", "Id [Team]", "Created at [Team]",
52
52
  "Updated at [Team]", "Name [Team]", "Logo url [Team]", "Team Manager [Team]", "Ballpark [Team]",
@@ -87,7 +87,7 @@ describe "RailsAdmin Export" do
87
87
  visit export_path(:model_name => 'comment')
88
88
  select "<comma> ','", :from => "csv_options_generator_col_sep"
89
89
  click_button 'Export to csv'
90
- csv = CSV.parse find('body').text
90
+ csv = CSV.parse page.driver.response.body
91
91
  expect(csv[0]).to match_array ["Id", "Commentable", "Commentable type", "Content", "Created at", "Updated at"]
92
92
  csv[1..-1].each do |line|
93
93
  expect(line[csv[0].index('Commentable')]).to eq(@player.id.to_s)
@@ -30,16 +30,17 @@ describe "RailsAdmin Basic List" do
30
30
 
31
31
  describe "GET /admin/player as list" do
32
32
  it "shows \"List of Models\", should show filters and should show column headers" do
33
- 21.times { FactoryGirl.create :player } # two pages of players
33
+ RailsAdmin.config.default_items_per_page = 1
34
+ 2.times { FactoryGirl.create :player } # two pages of players
34
35
  visit index_path(:model_name => "player")
35
36
  should have_content("List of Players")
36
37
  should have_content("Created at")
37
38
  should have_content("Updated at")
38
39
 
39
40
  # it "shows the show, edit and delete links" do
40
- should have_selector("td a", :text => 'Show')
41
- should have_selector("td a", :text => 'Edit')
42
- should have_selector("td a", :text => 'Delete')
41
+ should have_selector("li[title='Show'] a")
42
+ should have_selector("li[title='Edit'] a")
43
+ should have_selector("li[title='Delete'] a")
43
44
 
44
45
  # it "has the search box with some prompt text" do
45
46
  should have_selector("input[placeholder='Filter']")
@@ -55,14 +56,6 @@ describe "RailsAdmin Basic List" do
55
56
 
56
57
  describe "GET /admin/player" do
57
58
  before do
58
- RailsAdmin.config Player do
59
- list do
60
- field :name
61
- field :team
62
- field :injured
63
- field :retired
64
- end
65
- end
66
59
  @teams = 2.times.map do
67
60
  FactoryGirl.create(:team)
68
61
  end
@@ -75,6 +68,15 @@ describe "RailsAdmin Basic List" do
75
68
  end
76
69
 
77
70
  it "allows to query on any attribute" do
71
+ RailsAdmin.config Player do
72
+ list do
73
+ field :name
74
+ field :team
75
+ field :injured
76
+ field :retired
77
+ end
78
+ end
79
+
78
80
  visit index_path(:model_name => "player", :query => @players[0].name)
79
81
  should have_content(@players[0].name)
80
82
  (1..3).each do |i|
@@ -83,6 +85,15 @@ describe "RailsAdmin Basic List" do
83
85
  end
84
86
 
85
87
  it "allows to filter on one attribute" do
88
+ RailsAdmin.config Player do
89
+ list do
90
+ field :name
91
+ field :team
92
+ field :injured
93
+ field :retired
94
+ end
95
+ end
96
+
86
97
  visit index_path(:model_name => "player", :f => {:injured => {"1" => {:v => "true"}}})
87
98
  should have_content(@players[0].name)
88
99
  should have_no_content(@players[1].name)
@@ -91,6 +102,15 @@ describe "RailsAdmin Basic List" do
91
102
  end
92
103
 
93
104
  it "allows to combine filters on two different attributes" do
105
+ RailsAdmin.config Player do
106
+ list do
107
+ field :name
108
+ field :team
109
+ field :injured
110
+ field :retired
111
+ end
112
+ end
113
+
94
114
  visit index_path(:model_name => "player", :f => {:retired => {"1" => {:v => "true"}}, :injured => {"1" => {:v => "true"}}})
95
115
  should have_content(@players[0].name)
96
116
  (1..3).each do |i|
@@ -99,6 +119,15 @@ describe "RailsAdmin Basic List" do
99
119
  end
100
120
 
101
121
  it "allows to filter on belongs_to relationships" do
122
+ RailsAdmin.config Player do
123
+ list do
124
+ field :name
125
+ field :team
126
+ field :injured
127
+ field :retired
128
+ end
129
+ end
130
+
102
131
  visit index_path(:model_name => "player", :f => {:team => {"1" => { :v => @teams[0].name }}})
103
132
  should have_content(@players[0].name)
104
133
  should have_content(@players[1].name)
@@ -250,9 +279,9 @@ describe "RailsAdmin Basic List" do
250
279
  end
251
280
  end
252
281
 
253
- visit index_path(:model_name => "player")
254
- should have_content(%{$.filters.append("Name", "name", "string", null, null, "", 1);})
255
- should have_content(%{$.filters.append("Team", "team", "belongs_to_association", null, null, "", 2);})
282
+ get index_path(:model_name => "player")
283
+ expect(response.body).to include(%{$.filters.append("Name", "name", "string", "", null, "", 1);})
284
+ expect(response.body).to include(%{$.filters.append("Team", "team", "belongs_to_association", "", null, "", 2);})
256
285
  end
257
286
  end
258
287
 
@@ -267,19 +296,20 @@ describe "RailsAdmin Basic List" do
267
296
  end
268
297
  end
269
298
 
270
- describe "GET /admin/player with 20 objects" do
299
+ describe "GET /admin/player with 2 objects" do
271
300
  before(:each) do
272
- @players = 20.times.map { FactoryGirl.create :player }
301
+ @players = 2.times.map { FactoryGirl.create :player }
273
302
  visit index_path(:model_name => "player")
274
303
  end
275
304
 
276
- it "shows \"20 results\"" do
277
- should have_content("20 players")
305
+ it "shows \"2 results\"" do
306
+ should have_content("2 players")
278
307
  end
279
308
  end
280
309
 
281
310
  describe "GET /admin/player with 3 pages, page 2" do
282
- before(:each) do
311
+ before do
312
+ RailsAdmin.config.default_items_per_page = 1
283
313
  items_per_page = RailsAdmin.config.default_items_per_page
284
314
  (items_per_page * 3).times { FactoryGirl.create(:player) }
285
315
  visit index_path(:model_name => "player", :page => 2)
@@ -333,7 +363,7 @@ describe "RailsAdmin Basic List" do
333
363
  describe "list as compact json" do
334
364
  it "has_content an array with 2 elements and contain an array of elements with keys id and label" do
335
365
  2.times.map { FactoryGirl.create :player }
336
- response = page.driver.get(index_path(:model_name => "player", :compact => true, :format => :json))
366
+ get index_path(:model_name => "player", :compact => true, :format => :json)
337
367
  expect(ActiveSupport::JSON.decode(response.body).length).to eq(2)
338
368
  ActiveSupport::JSON.decode(response.body).each do |object|
339
369
  expect(object).to have_key("id")
@@ -12,9 +12,9 @@ describe "RailsAdmin Basic Update" do
12
12
 
13
13
  it "returns to edit page" do
14
14
  fill_in "player[name]", :with => ""
15
- click_button "Save"
15
+ click_button "Save" # first(:button, "Save").click
16
16
  expect(page.driver.status_code).to eq(406)
17
- should have_selector "form", :action => "/admin/players/#{@player.id}"
17
+ should have_selector "form[action='#{edit_path(:model_name => "player", :id => @player.id)}']"
18
18
  end
19
19
  end
20
20
 
@@ -27,7 +27,7 @@ describe "RailsAdmin Basic Update" do
27
27
  fill_in "player[name]", :with => "Jackie Robinson"
28
28
  fill_in "player[number]", :with => "42"
29
29
  fill_in "player[position]", :with => "Second baseman"
30
- click_button "Save"
30
+ click_button "Save" # first(:button, "Save").click
31
31
 
32
32
  @player = RailsAdmin::AbstractModel.new("Player").first
33
33
  end
@@ -65,7 +65,7 @@ describe "RailsAdmin Basic Update" do
65
65
  @player = FactoryGirl.create :player
66
66
  @draft = FactoryGirl.create :draft
67
67
  @number = @draft.player.number + 1 # to avoid collision
68
- page.driver.put edit_path(:model_name => "player", :id => @player.id, :player => {:name => "Jackie Robinson", :draft_id => @draft.id, :number => @number, :position => "Second baseman"})
68
+ put edit_path(:model_name => "player", :id => @player.id, :player => {:name => "Jackie Robinson", :draft_id => @draft.id, :number => @number, :position => "Second baseman"})
69
69
  @player.reload
70
70
  end
71
71
 
@@ -89,9 +89,9 @@ describe "RailsAdmin Basic Update" do
89
89
 
90
90
  @league = FactoryGirl.create :league
91
91
  @divisions = 3.times.map { Division.create!(:name => "div #{Time.now.to_f}", :league => League.create!(:name => "league #{Time.now.to_f}")) }
92
-
93
- page.driver.put edit_path(:model_name => "league", :id => @league.id, :league => {:name => "National League", :division_ids => [@divisions[0].id] })
94
-
92
+
93
+ put edit_path(:model_name => "league", :id => @league.id, :league => {:name => "National League", :division_ids => [@divisions[0].id] })
94
+
95
95
  old_name = @league.name
96
96
  @league.reload
97
97
  expect(@league.name).to eq("National League")
@@ -102,7 +102,7 @@ describe "RailsAdmin Basic Update" do
102
102
 
103
103
  expect(RailsAdmin::History.where(:item => @league.id).collect(&:message)).to include("name: \"#{old_name}\" -> \"National League\"")
104
104
 
105
- page.driver.put edit_path(:model_name => "league", :id => @league.id, :league => {:division_ids => [""]})
105
+ put edit_path(:model_name => "league", :id => @league.id, :league => {:division_ids => [""]})
106
106
 
107
107
  @league.reload
108
108
  expect(@league.divisions).to be_empty
@@ -111,11 +111,11 @@ describe "RailsAdmin Basic Update" do
111
111
 
112
112
  describe "update with missing object" do
113
113
  before(:each) do
114
- page.driver.put(edit_path(:model_name => "player", :id => 1), :params => {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
114
+ put edit_path(:model_name => "player", :id => 1), :params => {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}}
115
115
  end
116
116
 
117
117
  it "raises NotFound" do
118
- expect(page.driver.status_code).to eq(404)
118
+ expect(response.code).to eq("404")
119
119
  end
120
120
  end
121
121
 
@@ -128,7 +128,7 @@ describe "RailsAdmin Basic Update" do
128
128
  fill_in "player[name]", :with => "Jackie Robinson"
129
129
  fill_in "player[number]", :with => "a"
130
130
  fill_in "player[position]", :with => "Second baseman"
131
- click_button "Save"
131
+ click_button "Save" # first(:button, "Save").click
132
132
 
133
133
  @player.reload
134
134
  end
@@ -137,7 +137,7 @@ describe "RailsAdmin Basic Update" do
137
137
  # TODO: Mongoid 3.0.0 lacks ability of numericality validation on Integer field.
138
138
  # This is caused by change in https://github.com/mongoid/mongoid/pull/1698
139
139
  # I believe this should be a bug in Mongoid.
140
- expect(body).to have_content("Player failed to be updated") unless CI_ORM == :mongoid && Mongoid::VERSION >= '3.0.0'
140
+ expect(Capybara.string(body)).to have_content("Player failed to be updated") unless CI_ORM == :mongoid && Mongoid::VERSION >= '3.0.0'
141
141
  end
142
142
  end
143
143
 
@@ -154,7 +154,7 @@ describe "RailsAdmin Basic Update" do
154
154
  visit edit_path(:model_name => "user", :id => @user.id)
155
155
 
156
156
  fill_in "user[roles]", :with => %{['admin', 'user']}
157
- click_button "Save"
157
+ click_button "Save" # first(:button, "Save").click
158
158
 
159
159
  @user.reload
160
160
  end
@@ -174,7 +174,7 @@ describe "RailsAdmin Basic Update" do
174
174
  it "saves the serialized data" do
175
175
  fill_in "field_test[array_field]", :with => "[4, 2]"
176
176
  fill_in "field_test[hash_field]", :with => "{ a: 6, b: 2 }"
177
- click_button "Save"
177
+ click_button "Save" # first(:button, "Save").click
178
178
 
179
179
  @field_test.reload
180
180
  expect(@field_test.array_field).to eq([4, 2])
@@ -184,7 +184,7 @@ describe "RailsAdmin Basic Update" do
184
184
  it "clears data when empty string is passed" do
185
185
  fill_in "field_test[array_field]", :with => ""
186
186
  fill_in "field_test[hash_field]", :with => ""
187
- click_button "Save"
187
+ click_button "Save" # first(:button, "Save").click
188
188
 
189
189
  @field_test.reload
190
190
  expect(@field_test.array_field).to eq(nil)
@@ -16,7 +16,7 @@ describe "RailsAdmin Config DSL Edit Section" do
16
16
  end
17
17
  visit new_path(:model_name => "field_test")
18
18
  fill_in "field_test[format]", :with => "test for format"
19
- click_button "Save"
19
+ click_button "Save" # first(:button, "Save").click
20
20
  @record = RailsAdmin::AbstractModel.new("FieldTest").first
21
21
  expect(@record.format).to eq("test for format")
22
22
  end
@@ -93,7 +93,7 @@ describe "RailsAdmin Config DSL Edit Section" do
93
93
  fill_in "field_test[string_field]", :with => "No problem here"
94
94
  fill_in "field_test[restricted_field]", :with => "I'm allowed to do that as :custom_role only"
95
95
  should have_no_selector "field_test[protected_field]"
96
- click_button "Save"
96
+ click_button "Save" # first(:button, "Save").click
97
97
  @field_test = FieldTest.first
98
98
  expect(@field_test.string_field).to eq("No problem here")
99
99
  expect(@field_test.restricted_field).to eq("I'm allowed to do that as :custom_role only")
@@ -161,7 +161,10 @@ describe "RailsAdmin Config DSL Edit Section" do
161
161
  end
162
162
  end
163
163
  visit new_path(:model_name => "team")
164
- should have_selector("legend", :text => "Renamed group")
164
+ # NOTE: capybara 2.0 is exceedingly reluctant to reveal the text of invisible elements. This was
165
+ # the least terrible option I was able to find. It would probably be better to refactor the test
166
+ # so the label we're looking for is displayed.
167
+ expect(find("legend", :visible => false).native.text).to include("Renamed group")
165
168
  end
166
169
 
167
170
  describe "help" do
@@ -309,12 +312,8 @@ describe "RailsAdmin Config DSL Edit Section" do
309
312
  end
310
313
  end
311
314
  visit new_path(:model_name => "team")
312
- should have_selector("legend", :text => "Basic info")
313
- all("legend", :text => "Basic info").tap do |nodes|
314
- expect(nodes.count).to eq(2)
315
- expect(nodes.first.visible?).to be_false
316
- expect(nodes.last.visible?).to be_true
317
- end
315
+ should have_selector("legend", :text => "Basic info", :visible => false)
316
+ should have_selector("legend", :text => "Basic info", :visible => true)
318
317
  should have_selector("legend", :text => "Belong's to associations")
319
318
  should have_selector("label", :text => "Name")
320
319
  should have_selector("label", :text => "Logo url")
@@ -398,7 +397,7 @@ describe "RailsAdmin Config DSL Edit Section" do
398
397
  after :each do
399
398
  I18n.locale = :en
400
399
  end
401
-
400
+
402
401
  it "delegates the label option to the ActiveModel API and memoizes it" do
403
402
  RailsAdmin.config Team do
404
403
  edit do
@@ -611,10 +610,10 @@ describe "RailsAdmin Config DSL Edit Section" do
611
610
 
612
611
  visit new_path(:model_name => 'category')
613
612
  should have_no_css('#category_parent_category_id')
614
- click_button 'Save'
613
+ click_button "Save" # first(:button, "Save").click
615
614
  visit edit_path(:model_name => 'category', :id => Category.first)
616
615
  should have_css('#category_parent_category_id')
617
- click_button 'Save'
616
+ click_button "Save" # first(:button, "Save").click
618
617
  should have_content('Category successfully updated')
619
618
  end
620
619
  end
@@ -627,7 +626,7 @@ describe "RailsAdmin Config DSL Edit Section" do
627
626
  fill_in "field_test_comment_attributes_content", :with => 'nested comment content'
628
627
  fill_in "field_test_nested_field_tests_attributes_0_title", :with => 'nested field test title 1 edited'
629
628
  page.find('#field_test_nested_field_tests_attributes_1__destroy').set('true')
630
- click_button "Save"
629
+ click_button "Save" # first(:button, "Save").click
631
630
  @record.reload
632
631
  expect(@record.comment.content).to eq('nested comment content')
633
632
  expect(@record.nested_field_tests.length).to eq(1)
@@ -706,7 +705,7 @@ describe "RailsAdmin Config DSL Edit Section" do
706
705
  visit edit_path(:model_name => "field_test", :id => @record.id)
707
706
  fill_in "field_test_embeds_attributes_0_name", :with => 'embed 1 edited'
708
707
  page.find('#field_test_embeds_attributes_1__destroy').set('true')
709
- click_button "Save"
708
+ click_button "Save" # first(:button, "Save").click
710
709
  @record.reload
711
710
  expect(@record.embeds.length).to eq(1)
712
711
  expect(@record.embeds[0].name).to eq('embed 1 edited')