diff --git a/src/Orchard.Specs/Bindings/WebAppHosting.cs b/src/Orchard.Specs/Bindings/WebAppHosting.cs
index 3d3a6660e..94bd33e4f 100644
--- a/src/Orchard.Specs/Bindings/WebAppHosting.cs
+++ b/src/Orchard.Specs/Bindings/WebAppHosting.cs
@@ -170,8 +170,10 @@ namespace Orchard.Specs.Bindings {
[When(@"I follow ""(.*)""")]
public void WhenIFollow(string linkText) {
var link = _doc.DocumentNode
- .SelectNodes("//a")
- .Single(elt => elt.InnerText == linkText);
+ .SelectNodes("//a")
+ .SingleOrDefault(elt => elt.InnerText == linkText)
+ ?? _doc.DocumentNode
+ .SelectSingleNode(string.Format("//a[@title='{0}']", linkText));
var urlPath = link.Attributes["href"].Value;
diff --git a/src/Orchard.Specs/Orchard.Specs.csproj b/src/Orchard.Specs/Orchard.Specs.csproj
index 864d5388b..9b863ec27 100644
--- a/src/Orchard.Specs/Orchard.Specs.csproj
+++ b/src/Orchard.Specs/Orchard.Specs.csproj
@@ -206,6 +206,11 @@
True
WebHosting.feature
+
+ True
+ True
+ Widgets.feature
+
@@ -278,6 +283,10 @@
SpecFlowSingleFileGenerator
UsingSpecFlow.feature.cs
+
+ SpecFlowSingleFileGenerator
+ Widgets.feature.cs
+
diff --git a/src/Orchard.Specs/Widgets.feature b/src/Orchard.Specs/Widgets.feature
new file mode 100644
index 000000000..feed9f25f
--- /dev/null
+++ b/src/Orchard.Specs/Widgets.feature
@@ -0,0 +1,17 @@
+Feature: Widgets
+ In order to add and manage widgets on my site
+ As an author
+ I want to create and edit widgets and layers
+
+Scenario: I can edit a default layer
+ Given I have installed Orchard
+ When I go to "admin/widgets"
+ And I follow "Edit Default layer"
+ And I fill in
+ | name | value |
+ | Description | This is the default layer. |
+ And I hit "Save"
+ And I am redirected
+ Then I should see "Your Layer has been saved"
+ When I follow "Edit Default layer"
+ Then I should see ""
diff --git a/src/Orchard.Specs/Widgets.feature.cs b/src/Orchard.Specs/Widgets.feature.cs
new file mode 100644
index 000000000..a25672125
--- /dev/null
+++ b/src/Orchard.Specs/Widgets.feature.cs
@@ -0,0 +1,93 @@
+// ------------------------------------------------------------------------------
+//
+// This code was generated by SpecFlow (http://www.specflow.org/).
+// SpecFlow Version:1.4.0.0
+// Runtime Version:4.0.30319.1
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+// ------------------------------------------------------------------------------
+#region Designer generated code
+namespace Orchard.Specs
+{
+ using TechTalk.SpecFlow;
+
+
+ [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "1.4.0.0")]
+ [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [NUnit.Framework.TestFixtureAttribute()]
+ [NUnit.Framework.DescriptionAttribute("Widgets")]
+ public partial class WidgetsFeature
+ {
+
+ private static TechTalk.SpecFlow.ITestRunner testRunner;
+
+#line 1 "Widgets.feature"
+#line hidden
+
+ [NUnit.Framework.TestFixtureSetUpAttribute()]
+ public virtual void FeatureSetup()
+ {
+ testRunner = TechTalk.SpecFlow.TestRunnerManager.GetTestRunner();
+ TechTalk.SpecFlow.FeatureInfo featureInfo = new TechTalk.SpecFlow.FeatureInfo(new System.Globalization.CultureInfo("en-US"), "Widgets", "In order to add and manage widgets on my site\r\nAs an author\r\nI want to create and" +
+ " edit widgets and layers", GenerationTargetLanguage.CSharp, ((string[])(null)));
+ testRunner.OnFeatureStart(featureInfo);
+ }
+
+ [NUnit.Framework.TestFixtureTearDownAttribute()]
+ public virtual void FeatureTearDown()
+ {
+ testRunner.OnFeatureEnd();
+ testRunner = null;
+ }
+
+ public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
+ {
+ testRunner.OnScenarioStart(scenarioInfo);
+ }
+
+ [NUnit.Framework.TearDownAttribute()]
+ public virtual void ScenarioTearDown()
+ {
+ testRunner.OnScenarioEnd();
+ }
+
+ [NUnit.Framework.TestAttribute()]
+ [NUnit.Framework.DescriptionAttribute("I can edit a default layer")]
+ public virtual void ICanEditADefaultLayer()
+ {
+ TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("I can edit a default layer", ((string[])(null)));
+#line 6
+this.ScenarioSetup(scenarioInfo);
+#line 7
+ testRunner.Given("I have installed Orchard");
+#line 8
+ testRunner.When("I go to \"admin/widgets\"");
+#line 9
+ testRunner.And("I follow \"Edit Default layer\"");
+#line hidden
+ TechTalk.SpecFlow.Table table1 = new TechTalk.SpecFlow.Table(new string[] {
+ "name",
+ "value"});
+ table1.AddRow(new string[] {
+ "Description",
+ "This is the default layer."});
+#line 10
+ testRunner.And("I fill in", ((string)(null)), table1);
+#line 13
+ testRunner.And("I hit \"Save\"");
+#line 14
+ testRunner.And("I am redirected");
+#line 15
+ testRunner.Then("I should see \"Your Layer has been saved\"");
+#line 16
+ testRunner.When("I follow \"Edit Default layer\"");
+#line 17
+ testRunner.Then("I should see \"\"");
+#line hidden
+ testRunner.CollectScenarioErrors();
+ }
+ }
+}
+#endregion
diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Drivers/LayerPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Widgets/Drivers/LayerPartDriver.cs
index 7764af83e..8009bca01 100644
--- a/src/Orchard.Web/Modules/Orchard.Widgets/Drivers/LayerPartDriver.cs
+++ b/src/Orchard.Web/Modules/Orchard.Widgets/Drivers/LayerPartDriver.cs
@@ -33,18 +33,21 @@ namespace Orchard.Widgets.Drivers {
protected override DriverResult Editor(LayerPart layerPart, IUpdateModel updater, dynamic shapeHelper) {
if(updater.TryUpdateModel(layerPart, Prefix, null, null)) {
- if ( String.IsNullOrWhiteSpace(layerPart.LayerRule) ) {
+ if (String.IsNullOrWhiteSpace(layerPart.LayerRule)) {
layerPart.LayerRule = "true";
}
- if ( _widgetsService.GetLayers().Any(l => String.Equals(l.Name, layerPart.Name, StringComparison.InvariantCultureIgnoreCase))) {
+ if (_widgetsService.GetLayers()
+ .Any(l =>
+ l.Id != layerPart.Id
+ && String.Equals(l.Name, layerPart.Name, StringComparison.InvariantCultureIgnoreCase))) {
updater.AddModelError("Name", T("A Layer with the same name already exists"));
}
try {
_ruleManager.Matches(layerPart.LayerRule);
}
- catch ( Exception e ) {
+ catch (Exception e) {
updater.AddModelError("Description", T("The rule is not valid: {0}", e.Message));
}
}
diff --git a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml
index 4e4419e52..5bd16fc13 100644
--- a/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml
+++ b/src/Orchard.Web/Modules/Orchard.Widgets/Views/Admin/Index.cshtml
@@ -52,21 +52,16 @@