From c0f10e15d8d2ec3be620dff62315a44bd065f201 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 1 Oct 2012 14:59:29 -0700 Subject: Moving start to help engine to live within leap_web repo rather than independent engine repo. --- Gemfile | 1 + help/Gemfile | 20 +++++++++++ help/Rakefile | 38 ++++++++++++++++++++ help/app/models/ticket.rb | 59 ++++++++++++++++++++++++++++++++ help/app/models/ticket_comment.rb | 33 ++++++++++++++++++ help/config/routes.rb | 2 ++ help/leap_web_help.gemspec | 26 ++++++++++++++ help/lib/leap_web_help.rb | 4 +++ help/lib/leap_web_help/engine.rb | 10 ++++++ help/lib/leap_web_help/version.rb | 3 ++ help/lib/tasks/leap_web_help_tasks.rake | 4 +++ help/script/rails | 8 +++++ help/test/integration/navigation_test.rb | 9 +++++ help/test/leap_web_help_test.rb | 7 ++++ help/test/test_helper.rb | 15 ++++++++ help/test/unit/ticket_comment_test.rb | 46 +++++++++++++++++++++++++ help/test/unit/ticket_test.rb | 53 ++++++++++++++++++++++++++++ 17 files changed, 338 insertions(+) create mode 100644 help/Gemfile create mode 100644 help/Rakefile create mode 100644 help/app/models/ticket.rb create mode 100644 help/app/models/ticket_comment.rb create mode 100644 help/config/routes.rb create mode 100644 help/leap_web_help.gemspec create mode 100644 help/lib/leap_web_help.rb create mode 100644 help/lib/leap_web_help/engine.rb create mode 100644 help/lib/leap_web_help/version.rb create mode 100644 help/lib/tasks/leap_web_help_tasks.rake create mode 100755 help/script/rails create mode 100644 help/test/integration/navigation_test.rb create mode 100644 help/test/leap_web_help_test.rb create mode 100644 help/test/test_helper.rb create mode 100644 help/test/unit/ticket_comment_test.rb create mode 100644 help/test/unit/ticket_test.rb diff --git a/Gemfile b/Gemfile index f726042..015c5ad 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ gem 'simple_form' gem 'leap_web_core', :path => 'core' gem 'leap_web_users', :path => 'users' gem 'leap_web_certs', :path => 'certs' +gem 'leap_web_help', :path => 'help' gem 'couchrest_session_store' diff --git a/help/Gemfile b/help/Gemfile new file mode 100644 index 0000000..8dfcd78 --- /dev/null +++ b/help/Gemfile @@ -0,0 +1,20 @@ +source "http://rubygems.org" + +# Declare your gem's dependencies in leap_web_help.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# jquery-rails is used by the dummy application +gem "jquery-rails" + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use debugger + gem 'ruby-debug' + + # TODO: not sure I actually want this here, but trying: + gem 'therubyracer', :platforms => :ruby diff --git a/help/Rakefile b/help/Rakefile new file mode 100644 index 0000000..9306287 --- /dev/null +++ b/help/Rakefile @@ -0,0 +1,38 @@ +#!/usr/bin/env rake +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end +begin + require 'rdoc/task' +rescue LoadError + require 'rdoc/rdoc' + require 'rake/rdoctask' + RDoc::Task = Rake::RDocTask +end + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'LeapWebHelp' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + + + + +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + + +task :default => :test diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb new file mode 100644 index 0000000..8a282b5 --- /dev/null +++ b/help/app/models/ticket.rb @@ -0,0 +1,59 @@ +class Ticket < CouchRest::Model::Base + #include ActiveModel::Validations + + use_database "tickets" + require 'securerandom' +=begin + title + created_at + updated_at + email_address + user + user_verified? + admins (list of admins who have commented on the ticket) + code (secret url) +=end + + #belongs_to :user #from leap_web_users. doesn't necessarily belong to a user though + property :created_by, Integer #nil unless user was authenticated for ticket creation, #THIS should not be changed after being set + property :regarding_user, Integer # form cannot be submitted if they type in a username w/out corresponding ID. this field can be nil. for authenticated ticket creation by non-admins, should this just automatically be set to be same as created_by? or maybe we don't use this field unless created_by is nil? + #also, both created_by and regarding_user could be nil---say user forgets username, or has general question + property :title, String + property :email, String #verify + + #property :user_verified, TrueClass, :default => false #will be true exactly when user is set + #admins + property :code, String, :protected => true # only should be set if created_by is nil + property :comments, [TicketComment] + + timestamps! + + before_validation :set_code, :on => :create + + design do + view :by_title + end + + + validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/, :if => :email #email address is optional + + #set created_by to be current_user + + def is_creator_validated? + !!created_by + end + + def set_code + # ruby 1.9 provides url-safe option---this is not necessarily url-safe + self.code = SecureRandom.hex(8) if !is_creator_validated? + end + + +=begin + def validate + if email_address and not email_address.strip =~ RFC822::EmailAddress + errors.add 'email', 'contains an invalid address' + end + end +=end +end diff --git a/help/app/models/ticket_comment.rb b/help/app/models/ticket_comment.rb new file mode 100644 index 0000000..1e23136 --- /dev/null +++ b/help/app/models/ticket_comment.rb @@ -0,0 +1,33 @@ +class TicketComment < CouchRest::Model::Base #?? do we want this to be a base model? + include CouchRest::Model::Embeddable + + #use_database "ticket_comments" + + #belongs_to :ticket #is this best way to do it? will want to access all of a tickets comments, so maybe this isn't the way? + property :posted_by, Integer, :protected => true# maybe this should be current_user if that is set, meaning the user is logged in #String # user?? + # if the current user is not set, then we could just say the comment comes from an 'unauthenticated user', which would be somebody with the secret URL + property :posted_at, Time, :protected => true + #property :posted_verified, TrueClass, :protected => true #should be true if current_user is set when the comment is created + property :body, String + + before_validation :set_time, :set_posted_by, :on => :create # hmm, this requires object to be validated for these methods to be called, but if this is only embeddedable (which might be best), then not clear how to do this without manually validating. + + #design do + # view :by_posted_at + # view :by_body + #end + + def is_comment_validated? + !!posted_by + end + + def set_time + self.posted_at = Time.now + end + + def set_posted_by + #should be something like this, but current_user is not set yet + #self.posted_by = current_user if current_user + end + +end diff --git a/help/config/routes.rb b/help/config/routes.rb new file mode 100644 index 0000000..1daf9a4 --- /dev/null +++ b/help/config/routes.rb @@ -0,0 +1,2 @@ +Rails.application.routes.draw do +end diff --git a/help/leap_web_help.gemspec b/help/leap_web_help.gemspec new file mode 100644 index 0000000..19b59d7 --- /dev/null +++ b/help/leap_web_help.gemspec @@ -0,0 +1,26 @@ +$:.push File.expand_path("../lib", __FILE__) + +# Maintain your gem's version: +require "leap_web_help/version" +require "leap_web_core/dependencies" + +# Describe your gem and declare its dependencies: +Gem::Specification.new do |s| + s.name = "leap_web_help" + s.version = LeapWebHelp::VERSION + s.authors = ["TODO: Your name"] + s.email = ["TODO: Your email"] + s.homepage = "TODO" + s.summary = "TODO: Summary of LeapWebHelp." + s.description = "TODO: Description of LeapWebHelp." + + s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] + s.test_files = Dir["test/**/*"] + + s.add_dependency "rails", "~> 3.2.8" + s.add_dependency "leap_web_core", "~> 0.0.1" + + LeapWebCore::Dependencies.add_ui_gems_to_spec(s) + + # s.add_dependency "jquery-rails" +end diff --git a/help/lib/leap_web_help.rb b/help/lib/leap_web_help.rb new file mode 100644 index 0000000..f5b04aa --- /dev/null +++ b/help/lib/leap_web_help.rb @@ -0,0 +1,4 @@ +require "leap_web_help/engine" + +module LeapWebHelp +end diff --git a/help/lib/leap_web_help/engine.rb b/help/lib/leap_web_help/engine.rb new file mode 100644 index 0000000..2ff3e86 --- /dev/null +++ b/help/lib/leap_web_help/engine.rb @@ -0,0 +1,10 @@ +# thou shall require all your dependencies in an engine. +require "leap_web_core" +#require "leap_web_users" #necessary? + +LeapWebCore::Dependencies.require_ui_gems + +module LeapWebHelp + class Engine < ::Rails::Engine + end +end diff --git a/help/lib/leap_web_help/version.rb b/help/lib/leap_web_help/version.rb new file mode 100644 index 0000000..6a7c85d --- /dev/null +++ b/help/lib/leap_web_help/version.rb @@ -0,0 +1,3 @@ +module LeapWebHelp + VERSION = "0.0.1" +end diff --git a/help/lib/tasks/leap_web_help_tasks.rake b/help/lib/tasks/leap_web_help_tasks.rake new file mode 100644 index 0000000..1f38982 --- /dev/null +++ b/help/lib/tasks/leap_web_help_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :leap_web_help do +# # Task goes here +# end diff --git a/help/script/rails b/help/script/rails new file mode 100755 index 0000000..5676ab9 --- /dev/null +++ b/help/script/rails @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. + +ENGINE_ROOT = File.expand_path('../..', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/leap_web_help/engine', __FILE__) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/help/test/integration/navigation_test.rb b/help/test/integration/navigation_test.rb new file mode 100644 index 0000000..eec8c0e --- /dev/null +++ b/help/test/integration/navigation_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' + +class NavigationTest < ActionDispatch::IntegrationTest + + # test "the truth" do + # assert true + # end +end + diff --git a/help/test/leap_web_help_test.rb b/help/test/leap_web_help_test.rb new file mode 100644 index 0000000..d74c087 --- /dev/null +++ b/help/test/leap_web_help_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class LeapWebHelpTest < ActiveSupport::TestCase + test "truth" do + assert_kind_of Module, LeapWebHelp + end +end diff --git a/help/test/test_helper.rb b/help/test/test_helper.rb new file mode 100644 index 0000000..1e26a31 --- /dev/null +++ b/help/test/test_helper.rb @@ -0,0 +1,15 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("../dummy/config/environment.rb", __FILE__) +require "rails/test_help" + +Rails.backtrace_cleaner.remove_silencers! + +# Load support files +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +# Load fixtures from the engine +if ActiveSupport::TestCase.method_defined?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +end diff --git a/help/test/unit/ticket_comment_test.rb b/help/test/unit/ticket_comment_test.rb new file mode 100644 index 0000000..37e6e67 --- /dev/null +++ b/help/test/unit/ticket_comment_test.rb @@ -0,0 +1,46 @@ +require 'test_helper' + +class TicketCommentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end + +=begin + setup do + @sample_ticket = Ticket.create :title => 'test ticket' + @sample_ticket.save + end +=end + + test "create" do + + comment2 = TicketComment.new :body => "help my email is broken!" + assert comment2.valid? + assert_not_nil comment2.posted_at + assert_nil comment2.posted_by #if not logged in + + #comment.ticket = testticket #Ticket.find_by_title("testing") + #assert_equal testticket.title, comment.ticket.title + + #tc.ticket = Ticket.find_by_title("test title") + #tc.ticket.title + end + + test "add comments" do + testticket = Ticket.create :title => "testing" + assert_equal testticket.comments.count, 0 + comment = TicketComment.new :body => "my email broke" + assert comment.valid? #validating or saving necessary for setting posted_at + assert_not_nil comment.posted_at + + testticket.comments << comment + assert_equal testticket.comments.count, 1 + sleep(1) # so first comment has earlier posted_at time + comment2 = TicketComment.new :body => "my email broke" + comment2.save #possible to save only if ticketcomment is a model now + testticket.comments << comment2 + assert_equal testticket.comments.count, 2 + assert testticket.comments.first.posted_at < testticket.comments.last.posted_at + end + +end diff --git a/help/test/unit/ticket_test.rb b/help/test/unit/ticket_test.rb new file mode 100644 index 0000000..fddd719 --- /dev/null +++ b/help/test/unit/ticket_test.rb @@ -0,0 +1,53 @@ +require 'test_helper' + +class TicketTest < ActiveSupport::TestCase + #test "the truth" do + # assert true + #end + + setup do + @sample = Ticket.new + end + + test "validity" do + t = Ticket.create :title => 'test title', :email => 'blah@blah.com' + assert t.valid? + assert_equal t.title, 'test title' + + #user = LeapWebHelp::User.new(User.valid_attributes_hash) + #user = LeapWebUsers::User.create + + #t.user = user + + #t.email = '' #invalid + #assert !t.valid? + #t.email = 'blah@blah.com, bb@jjj.org' + #assert t.valid? + t.email = 'bdlfjlkasfjklasjf' #invalid + #p t.email_address + #p t.email_address.strip =~ RFC822::EmailAddress + assert !t.valid? + end + + test "creation validated" do + assert !@sample.is_creator_validated? + #p current_user + @sample.created_by = 22 #current_user + assert @sample.is_creator_validated? + end + + test "code if & only if not creator-validated" do + t1 = Ticket.create :title => 'test title' + assert_not_nil t1.code + assert_nil t1.created_by + + t2 = Ticket.create :title => 'test title', :created_by => 4 + assert_nil t2.code + assert_not_nil t2.created_by + + + end + +end + + -- cgit v1.2.3