forked from gigix/ohfy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm 1.9.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
class Execution < ActiveRecord::Base | ||
belongs_to :plan | ||
has_many :activities | ||
has_many :habits, :through => :plan | ||
|
||
def act!(habit_id) | ||
self.activities.create!(:habit_id => habit_id) | ||
end | ||
|
||
class Status | ||
GREAT = 'great' | ||
GOOD = 'good' | ||
BAD = 'bad' | ||
UNKNOWN = 'unknown' | ||
end | ||
|
||
def status | ||
return Status::UNKNOWN if self.date > Date.today | ||
acted_habits = self.habits.select{|habit| acted?(habit) } | ||
if acted_habits.blank? | ||
return self.date == Date.today ? Status::UNKNOWN : Status::BAD | ||
end | ||
return Status::GREAT if acted_habits.size == self.habits.size | ||
return Status::GOOD | ||
end | ||
|
||
private | ||
def acted?(habit) | ||
not self.activities.find_by_habit_id(habit).blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Habit < ActiveRecord::Base | ||
belongs_to :plan | ||
has_many :activities | ||
has_many :activities | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
require 'spec_helper' | ||
|
||
describe Execution do | ||
|
||
before(:each) do | ||
@user = create_test_user | ||
@plan = @user.create_plan!((Date.today - 3), ['Drawing', 'Guitar', 'Gym']) | ||
end | ||
|
||
describe :status do | ||
it "returns GREAT if all habits are acted" do | ||
date = Date.today - 3 | ||
execution = @plan.execution_on(date) | ||
|
||
lambda do | ||
execution.habits.each{|habit| execution.act!(habit.id) } | ||
end.should change(Activity, :count).by(3) | ||
|
||
execution.status.should == Execution::Status::GREAT | ||
end | ||
|
||
it "returns GOOD if some habits are acted" do | ||
execution = @plan.execution_on(Date.today - 2) | ||
execution.act!(execution.habits.first) | ||
execution.status.should == Execution::Status::GOOD | ||
end | ||
|
||
it "returns BAD if no habit is acted" do | ||
@plan.execution_on(Date.today - 1).status.should == Execution::Status::BAD | ||
end | ||
|
||
it "returns UNKNOWN for future dates" do | ||
@plan.execution_on(Date.tomorrow).status.should == Execution::Status::UNKNOWN | ||
end | ||
|
||
it "returns UNKNOWN if no habit is acted for today" do | ||
execution = @plan.execution_on(Date.today) | ||
execution.status.should == Execution::Status::UNKNOWN | ||
|
||
execution.act!(execution.habits.first) | ||
execution.status.should == Execution::Status::GOOD | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
require 'spec_helper' | ||
|
||
describe Plan do | ||
describe :execution_on do | ||
before(:each) do | ||
@user = create_test_user | ||
@plan = @user.create_plan!((Date.today - 3), ['Drawing', 'Guitar', 'Gym']) | ||
end | ||
|
||
it "returns execution on given date" do | ||
@plan.execution_on(Date.today).date.should == Date.today | ||
end | ||
|
||
it "returns nil if given date is out of range" do | ||
@plan.execution_on(Date.today - 10).should be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version='1.0' encoding='utf-8' ?> | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<html> | ||
<head> | ||
<script type="text/javascript">var _sf_startpt=(new Date()).getTime()</script> | ||
<meta content='text/html; charset=utf-8' http-equiv='content-type' /> | ||
<title>Opscode Management</title> | ||
<link rel="Stylesheet" type="text/css" href="/stylesheets/base.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/themes/opscode/style.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/chef.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/facebox/facebox.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jquery-ui-1.7.1.custom.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jquery.treeTable.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/jsonedit_main.css" media="all" charset="utf-8" /><link rel="Stylesheet" type="text/css" href="/stylesheets/loading.css" media="all" charset="utf-8" /> | ||
<script type="text/javascript" src="/javascripts/jquery-1.3.2.min.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.jeditable.mini.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.livequery.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.localscroll.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.scrollTo.js" charset="utf-8"></script><script type="text/javascript" src="/javascripts/jquery.tools.min.js" charset="utf-8"></script> | ||
<script type="text/javascript" src="/facebox/facebox.js" charset="utf-8"></script> | ||
<script type="text/javascript" src="/javascripts/jquery-ui-1.7.1.custom.min.js" charset="utf-8"></script> | ||
<script type="text/javascript" src="/javascripts/jquery.treeTable.min.js" charset="utf-8"></script> | ||
<script type="text/javascript" src="/javascripts/chef.js" charset="utf-8"></script> | ||
|
||
</head> | ||
<body> | ||
<div id='container'> | ||
<div id='header'> | ||
<h1> | ||
<a href="http://www.opscode.com"><img src="/images/logo.png" /></a> | ||
<a href="/nodes">thoughtworkers</a> | ||
</h1> | ||
<div id='user-navigation'> | ||
<ul> | ||
<li>Logged in as: <a href="http://cookbooks.opscode.com/users/gigix">gigix</a></li> | ||
<li>|</li> | ||
<li><a href="/organizations">Organizations</a></li> | ||
<li>|</li> | ||
<li><a method="get" href="/logout" confirm="Are you sure you want to logout?">Logout</a></li> | ||
</ul> | ||
<div class='clear'></div> | ||
</div> | ||
<div id='main-navigation'> | ||
<ul> | ||
<li class=''><a href="/search">Search</a></li> | ||
<li class=''><a href="/status">Status</a></li> | ||
<li class=''><a href="/roles">Roles</a></li> | ||
<li class=''><a href="/nodes">Nodes</a></li> | ||
<li class=''><a href="/cookbooks">Cookbooks</a></li> | ||
<li class=''><a href="/databags">Data bags</a></li> | ||
<li class=''><a href="/clients">Clients</a></li> | ||
<li class=''><a href="/groups">Groups</a></li> | ||
<li class=''><a href="/users">Users</a></li> | ||
</ul> | ||
<div class='clear'></div> | ||
</div> | ||
</div> | ||
<div id='wrapper'> | ||
<div id='main'> | ||
<div id="container"> | ||
|
||
<div id="main-container"> | ||
<h3>Page not found.</h3> | ||
</div> | ||
<br /> | ||
<br /> | ||
</div> | ||
<div id='footer'> | ||
<div class='block'> | ||
<p>Copyright © 2010 Opscode</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div id='sidebar'> | ||
<div class='block notice' id='sidebar_block_notice'> | ||
<h4>Need Help?</h4> | ||
<p>If you have questions, or you're stuck, we're here to help.</p> | ||
<p> | ||
<a href='http://help.opscode.com/home' target='_blank'>Get Help</a> | ||
or | ||
<a href='#'>Leave Feedback</a> | ||
</p> | ||
</div> | ||
<div class='block' id='sidebar_block'></div> | ||
</div> | ||
<div class='clear'></div> | ||
</div> | ||
<script src='/javascripts/tender_widget.js' type='text/javascript'></script> | ||
</div> | ||
</body> | ||
</html> |