Skip to content

Commit

Permalink
- Updated the RavenDb logo image.
Browse files Browse the repository at this point in the history
- Added another unit test.
- Fixed up asking a question with validation handling. UI isn't perfect still.
- Not all fake questions create votes.
- Asking a question requires authorization.
- BugFix: questions with a null Vote doesn't crash the view.
  • Loading branch information
PureKrome committed Jan 23, 2012
1 parent 843aa36 commit d91867b
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Code/RavenOverflow.Core/Entities/Question.cs
Expand Up @@ -19,7 +19,7 @@ public Question()
public DateTime CreatedOn { get; set; } // This should always be Utc.
[Required]
public ICollection<string> Tags { get; set; }
[Required]
[Required(ErrorMessage = "You need to be logged in to ask a question.")]
public string CreatedByUserId { get; set; }
public ICollection<Answer> Answers { get; set; }
public int NumberOfViews { get; set; }
Expand Down
14 changes: 8 additions & 6 deletions Code/RavenOverflow.FakeData/FakeQuestions.cs
Expand Up @@ -131,12 +131,14 @@ private static Comment CreateAFakeComment(DateTime questionCreatedOn)

private static Vote CreateAFakeVote()
{
return Builder<Vote>
.CreateNew()
.With(y => y.UpVoteCount = GetRandom.PositiveInt(20))
.And(y => y.DownVoteCount = GetRandom.PositiveInt(3))
.And(y => y.FavoriteCount = GetRandom.PositiveInt(10))
.Build();
return GetRandom.PositiveInt(5) == 1
? null
: Builder<Vote>
.CreateNew()
.With(y => y.UpVoteCount = GetRandom.PositiveInt(20))
.And(y => y.DownVoteCount = GetRandom.PositiveInt(3))
.And(y => y.FavoriteCount = GetRandom.PositiveInt(10))
.Build();
}

private static IList<Question> CreateFixedFakeQuestions(IList<string> userIds)
Expand Down
30 changes: 29 additions & 1 deletion Code/RavenOverflow.Tests/Controllers/QuestionControllerFacts.cs
Expand Up @@ -32,6 +32,34 @@ public QuestionControllerFacts()
Mapper.AssertConfigurationIsValid();
}

[Fact]
public void GivenAnInValidQuestion_Create_ReturnsAResultView()
{
using (IDocumentSession documentSession = DocumentStore.OpenSession())
{
// Arrange.
IQuestionService questionService = new QuestionService(documentSession);
QuestionsController questionsController = new QuestionsController(documentSession, questionService);
ControllerUtilities.SetUpControllerContext(questionsController);
CreateInputModel createInputModel = new CreateInputModel
{
Content = "Some content",
Subject = null, // RuRoh - dat ist missin'
Tags = "tag1 tag2 tag3-3-3"
};

// Now pretend the model binding raised an error with the input model.
questionsController.ModelState.AddModelError("key", "error message");

// Act.
var result = questionsController.Create(createInputModel) as ViewResult;

// Assert.
Assert.NotNull(result);
Assert.Equal("Create", result.ViewName);
}
}

[Fact]
public void GivenAValidQuestionAndNoOneIsLoggedIn_Create_ReturnsAResultView()
{
Expand All @@ -52,7 +80,7 @@ public void GivenAValidQuestionAndNoOneIsLoggedIn_Create_ReturnsAResultView()

// Assert.
Assert.NotNull(result);
//Assert.Equal("Create", result.ViewName);
Assert.Equal("Create", result.ViewName);
}
}

Expand Down
@@ -1,4 +1,5 @@
using System.Web.Mvc;
using System;
using System.Web.Mvc;
using AutoMapper;
using Raven.Client;
using RavenOverflow.Core.Services;
Expand All @@ -24,10 +25,10 @@ public ActionResult Create()
{
Header = "Ask a Question"
};
return View(viewModel);
return View("Create", viewModel);
}

[HttpPost, RavenActionFilter]
[HttpPost, RavenActionFilter, Authorize]
public ActionResult Create(CreateInputModel inputModel)
{
try
Expand All @@ -38,7 +39,7 @@ public ActionResult Create(CreateInputModel inputModel)
{
Header = "Ask a Question"
});
return View(viewModel);
return View("Create", viewModel);
}

Core.Entities.Question question = Mapper.Map<CreateInputModel, Core.Entities.Question>(inputModel);
Expand All @@ -48,13 +49,14 @@ public ActionResult Create(CreateInputModel inputModel)

return RedirectToAction("Index", "Home", new { area = "" });
}
catch
catch(Exception exception)
{
ModelState.AddModelError("RuRoh", exception.Message);
CreateViewModel viewModel = Mapper.Map(inputModel, new CreateViewModel(User.Identity)
{
Header = "Ask a Question"
});
return View(viewModel);
return View("Create", viewModel);
}
}
}
Expand Down
Expand Up @@ -4,13 +4,13 @@ namespace RavenOverflow.Web.Areas.Question.Models.ViewModels
{
public class CreateInputModel
{
[Required(ErrorMessage = "A Subject is required.")]
[Required(ErrorMessage = "A subject is missing.")]
public string Subject { get; set; }

[Required(ErrorMessage = "A question is required.")]
[Required(ErrorMessage = "A question is missing.")]
public string Content { get; set; }

[Required(ErrorMessage = "Some tags are required.")]
[Required(ErrorMessage = "you need at least one valid tag.")]
public string Tags { get; set; }
}
}
Expand Up @@ -24,22 +24,22 @@
<label for="title">Title</label>
</td>
<td class="ask-title-cell-value">
<input type="text" maxlength="300" tabindex="100" class="actual-edit-overlay" value="" style="position: absolute; background-color: white; color: black; -webkit-text-fill-color: black; opacity: 1; width: 610px; height: 16px; line-height: normal; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; text-align: -webkit-auto; border-left-style: solid; border-right-style: solid; border-top-style: solid; border-bottom-style: solid; border-left-color: rgb(153, 153, 153); border-right-color: rgb(153, 153, 153); border-top-color: rgb(153, 153, 153); border-bottom-color: rgb(153, 153, 153); border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; " disabled="disabled"><input id="title" name="title" type="text" maxlength="300" tabindex="100" class="ask-title-field edit-field-overlayed" value="" style="z-index: 1; position: relative; opacity: 0.4; ">
@Html.EditorFor(x => x.Subject, new { @class = "ask-title-field edit-field-overlayed", maxlength = "300" })
</td>
</tr>
</tbody>
</table>
<div id="question-suggestions">
</div>
</div>
<div id="post-editor" class="post-editor">
<textarea id="question" name="question" class="wmd-input processed" cols="92" rows="15" tabindex="101"></textarea>
<div id="post-editor" class="post-editor">
@Html.TextAreaFor(x => x.Content, new { @class = "wmd-input processed", cols = "92", rows = "15" })
</div>
<div class="form-item">
<label>Tags</label>
<input id="tags" name="tags" type="text" size="60" value="">
@Html.EditorFor(x => x.Tags, new { maxlength = "300"})
</div>

@Html.ValidationSummary("Oops! Your question couldn't be submitted because:", new { @class="form-error"})

<p>
<input type="submit" value="Ask Question"/>
</p>
Expand Down
Binary file added Code/RavenOverflow.Web/Content/logo-ravendb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -4,7 +4,7 @@ namespace RavenOverflow.Web.Models.ViewModels
{
public class TagListViewModel
{
public IList<string> Tags { get; set; }
public ICollection<string> Tags { get; set; }
public bool IsUserTags { get; set; }
}
}
1 change: 1 addition & 0 deletions Code/RavenOverflow.Web/RavenOverflow.Web.csproj
Expand Up @@ -154,6 +154,7 @@
<Compile Include="Models\ViewModels\AuthenticationViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\logo-ravendb.png" />
<Content Include="Global.asax" />
<Content Include="Content\Site.css" />
<Content Include="Web.config" />
Expand Down
2 changes: 1 addition & 1 deletion Code/RavenOverflow.Web/Views/Shared/_Layout.cshtml
Expand Up @@ -38,7 +38,7 @@
<br class="cbt">

<div id="hlogo">
<img src="http://ravendb.net/static/logo/RavenDBlogo.png" height="61px" alt="RavenDb"/>
<img src="/Content/logo-ravendb.png" alt="RavenDb"/>
</div>

<div id="hmenus">
Expand Down
8 changes: 4 additions & 4 deletions Code/RavenOverflow.Web/Views/Shared/_QuestionList.cshtml
@@ -1,18 +1,18 @@
@using RavenOverflow.Web.Models.ViewModels
@using RavenOverflow.Web.Models
@model IList<QuestionListViewModel>
@model QuestionListViewModel

@if (Model == null || Model.Count <= 0)
@if (Model == null || Model.Questions == null || Model.Questions.Count <= 0)
{
<p>No questions have been asked.</p>
}
else
{
foreach (var question in Model)
foreach (var question in Model.Questions)
{
<div class="question-summary narrow" id="question-summary-@question.Id">
<div class="votes">
<div class="mini-counts">@((question.Vote.UpVoteCount - question.Vote.DownVoteCount).ToSimplifiedNumberText())</div>
<div class="mini-counts">@((question.Vote == null ? 0 : question.Vote.UpVoteCount - question.Vote.DownVoteCount).ToSimplifiedNumberText())</div>
<div>votes</div>
</div>

Expand Down
@@ -1,6 +1,6 @@
@using System.Text
@using RavenOverflow.Web.Models.ViewModels
@model IList<string>
@model ICollection<string>

@if (Model == null || Model.Count <= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion Code/RavenOverflow.Web/Web.config
Expand Up @@ -30,7 +30,7 @@
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
<forms loginUrl="~/Users/Authenticate" timeout="2880" />
</authentication>
<pages>
<namespaces>
Expand Down

0 comments on commit d91867b

Please sign in to comment.