Skip to content

Commit 53a3b6f

Browse files
committed
Replaced failing functional tests with failing cucumber scenarios. Portlets are broken (can't be edited or deleted).
1 parent 76ff38d commit 53a3b6f

File tree

8 files changed

+83
-34
lines changed

8 files changed

+83
-34
lines changed

features/portlets.feature

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,34 @@ Feature: Portlets
2828
When I go to the content library
2929
And follow "Portlet"
3030
Then I should see the following content:
31-
| A new portlet |
31+
| A new portlet |
32+
33+
# Portlets aren't deleting or updating due to errors with dynamic attributes.
34+
Scenario: Deleting a portlet
35+
Given I am logged in as a Content Editor
36+
And there is a "Portlet" with:
37+
| name | template |
38+
| A new portlet | Hello World |
39+
When I delete that portlet
40+
And I go to the content library
41+
And I click on "Portlet"
42+
And I should not see "A new portlet"
43+
When I view that portlet
44+
Then the response should be 500
45+
46+
# Portlets aren't deleting or updating due to errors with dynamic attributes.
47+
Scenario: Editing a portlet
48+
Given I am logged in as a Content Editor
49+
And there is a "Portlet" with:
50+
| name | template |
51+
| A new portlet | Hello World |
52+
When I edit that portlet
53+
And fill in "Name" with "New Name"
54+
And fill in "Template" with "New World"
55+
And I click on "Save"
56+
Then I should see the following content:
57+
| View Portlet 'New Name' |
58+
| New World |
59+
And I should not see the following content:
60+
| A new portlet |
61+
| Hello World |

features/step_definitions/content_pages_steps.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
assert page.has_content?(page_title)
55
end
66

7+
78
Given /^I am logged in as a Content Editor$/ do
89
visit '/cms'
910
fill_in 'login', :with => 'cmsadmin'
@@ -58,4 +59,8 @@
5859
end
5960
Then /^I should see a list of selectable content types$/ do
6061
pending
62+
end
63+
64+
When /^I click on "([^"]*)"$/ do |name|
65+
click_on name
6166
end

features/step_definitions/data_steps.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
end
55
end
66

7-
7+
When /^I should not see the following content:$/ do |table|
8+
table.raw.each do |row|
9+
refute page.has_content?(row[0]), "Found #{row[0]}' on the page when it was not expected to be there."
10+
end
11+
end
812

913

1014
# Creates a CMS::FileBlock
@@ -30,9 +34,9 @@
3034
# | name | content |
3135
# | A | B |
3236
When /^there is a "([^"]*)" with:$/ do |model_class, table|
33-
Factory(model_class.underscore.to_sym, table.hashes.first)
37+
@subject = Factory(model_class.underscore.to_sym, table.hashes.first)
3438
end
3539

3640
When /^there is a page with:$/ do |table|
3741
Factory(:public_page, { :publish_on_save=>true }.merge(table.hashes.first))
38-
end
42+
end
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# Steps for portlet.features
1+
# Steps for portlet.features
2+
When /^I delete that portlet$/ do
3+
# cms_portlet_path(@subject) seemed to create a wrong path: /cms/portlets.1 rather than the below statement
4+
page.driver.delete "/cms/portlets/#{@subject.id}"
5+
end
6+
When /^I view that portlet$/ do
7+
visit cms_portlet_path(@subject)
8+
end
9+
When /^I edit that portlet$/ do
10+
visit edit_cms_portlet_path(@subject)
11+
end

test/functional/cms/portlets_controller_test.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ def test_index
1515
assert_select "#dynamic_portlet_#{@block.id}"
1616
end
1717

18-
def test_index_does_not_show_deleted_portlets
19-
@block.destroy
20-
get :index
21-
assert_response :success
22-
assert_select "#dynamic_portlet_#{@block.id}", 0
23-
end
24-
2518
def test_show
2619
get :show, :id => @block.id
2720
assert_response :success
@@ -41,12 +34,6 @@ def test_edit
4134
assert_select "h1", "Edit Portlet 'V1'"
4235
end
4336

44-
def test_destroy
45-
delete :destroy, :id => @block.id
46-
assert_redirected_to cms_portlets_path
47-
assert_raise(ActiveRecord::RecordNotFound) { DynamicPortlet.find(@block.id) }
48-
end
49-
5037
def test_usages
5138
@page = Factory(:page, :section => root_section, :name => "Test Page", :path => "test")
5239
@page.create_connector(@block, "main")

test/unit/behaviors/dynamic_attributes_test.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ def setup
6565
assert_equal("Paper", @thing.description)
6666
end
6767

68-
#test "Always respond_to something=" do
69-
# assert_equal(true, Thing.respond_to?(:price=))
70-
# assert_equal true, @thing.respond_to?(:price=)
71-
# assert(Thing.respond_to?(:a=))
72-
# assert_equal(false, @thing.respond_to?(:price))
73-
# assert_equal(false, @thing.respond_to?("=".to_sym))
74-
#end
75-
7668
test "can bulk set persistent properties during construction" do
7769
mineral = Thing.new(:description=>"Rock")
7870
mineral.save!

test/unit/models/portlet_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ class EditablePortlet < Cms::Portlet
2020

2121
class PortletTest < ActiveSupport::TestCase
2222

23+
def setup
24+
@portlet = Factory(:portlet)
25+
26+
end
27+
test "destroy should mark a portlet as deleted" do
28+
@portlet.destroy
29+
@portlet.reload!
30+
Cms::Portlet.find(@portlet.id)
31+
assert_raise(ActiveRecord::RecordNotFound){
32+
Cms::Portlet.find(@portlet.id)
33+
}
34+
end
35+
36+
test "update_attributes" do
37+
@portlet.update_attributes(:b => "whatever")
38+
assert_equal "whatever", @portlet.b
39+
end
40+
41+
test "attributes=" do
42+
@portlet.attributes=({:b => "b"})
43+
assert_equal "b", @portlet.b
44+
end
2345
def test_dynamic_attributes
2446
portlet = DynamicPortlet.create(:name => "Test", :foo => "FOO")
2547
assert_equal "FOO", Cms::Portlet.find(portlet.id).foo

upgrading_to_3_1.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ http://freelancing-gods.com/posts/combustion_better_rails_engine_testing
2828
Start HERE
2929
---------
3030

31+
Replace integration tests with cucumber features.
3132

32-
Start working on functional tests. There are several broken file upload based on things which are likely brittle tests
3333

34-
Finishing tests:
35-
36-
2. Replace any broken functional tests with a cucumber test.
37-
38-
rake test:functionals
39-
test/functional/cms/portlets_controller_test.rb:47:in `test_destroy']:
40-
Unit tests leave seed data in DB.
34+
# Problem: Portlets cannot be deleted or updated
35+
Why: update_attributes is calling assign_attributes, which doesn't appear to be present on instances of a portlet for reasons I don't understand. Dynamic attributes
36+
are complicating matters again.
4137

38+
Other alternatives:
39+
1. Continue to patch dynamic attributes
40+
2. Rip it out, replace with something like 'json_record' (https://github.com/bdurand/json_record) which would allow us to store in a single column.

0 commit comments

Comments
 (0)