my_todo 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 11fb2e187ffec36175b7a00d524d44b08348e015
4
+ data.tar.gz: def56ca74f0e9820e8478b2f85d16a92498db27d
5
+ SHA512:
6
+ metadata.gz: 88b18aa11672994d46ac6a3f62070baf57dc0a188e60b44c470c2ba01525fa7ea1b876ed0c2af3dd9b5d41acddd20235106d8837fdf2bef09603813103f2ccb1
7
+ data.tar.gz: dbe30f3a1a8bb02345f6128517f8e1deed00570d8744cc972654dd476dff71886e6997e82db7a4e181bae95d99e94e1943511923d25e1ab84182926c283c4ba1
@@ -0,0 +1,6 @@
1
+ db:
2
+ seeds: lib/db/seeds.rb
3
+ migrate: lib/db/migrate
4
+ schema: lib/db/schema.rb
5
+ config:
6
+ database: lib/db/config.yml
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in my_todo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Vell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ ## Installation
2
+
3
+ To install this gem onto your system
4
+
5
+ ```ruby
6
+ gem install my_todo
7
+ ```
8
+
9
+ ## setup
10
+ Create and migrate the DB
11
+
12
+ `my_todo rake db:migrate`
13
+
14
+ ## Usage
15
+ Simply type `my_todo` to see a list of commands
16
+
17
+ Example of creating a todo item
18
+
19
+ ```ruby
20
+ my_todo create --body='hello world'
21
+ ```
22
+
23
+ will display
24
+
25
+ ```
26
+ ToDo CREATED!
27
+
28
+
29
+ ID: 4
30
+ ToDo: hello world
31
+ Tags: default
32
+ Complete: false
33
+ ```
34
+
35
+ Example of listing pending todos
36
+
37
+ ```ruby
38
+ my_todo list
39
+ ```
40
+
41
+ will display
42
+
43
+ ```
44
+ ToDos FOUND: 1
45
+
46
+
47
+ ID: 3
48
+ ToDo: hello world
49
+ Tags: default
50
+ Complete: false
51
+ ```
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then `RAILS_ENV=development bin/my_todo rake db:migrate` to create the development DB. You can also run `RAILS_ENV=development bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ NOTE: In development, all commands must be run with the RAILS_ENV included. This is to make sure any changes made go to the right db. Any commands ran without the RAILS_ENV specified will default to production.
58
+
59
+ ## Testing
60
+
61
+ Run `RAILS_ENV=test bin/my_todo rake db:migrate` to create the test db. Then run `rake` to run the RSpec tests.
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vmcilwain/my_todo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'standalone_migrations'
4
+
5
+ StandaloneMigrations::Tasks.load_tasks
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "my_todo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/my_todo ADDED
@@ -0,0 +1,50 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # @author Lovell McIlwain
4
+ #
5
+ # Sets running environment for application (standalone_migration/ActiveRecord).
6
+ # @note defaults to production unless rails environment is manually specified
7
+ # @note example: RAILS_ENV=development todo list
8
+ ENV['RAILS_ENV'] = ENV['RAILS_ENV'].nil? || ENV['RAILS_ENV'].empty? ? 'production' : ENV['RAILS_ENV']
9
+
10
+ # Set gem directory path
11
+ gem_dir = "#{__dir__}/.."
12
+
13
+ # Look in gem directory for resources first.
14
+ $LOAD_PATH.unshift gem_dir
15
+
16
+ # Stores argement passed to the executable
17
+ exec_type = ARGV[0]
18
+
19
+ # Runs rake tasks from my_todo gem once it's installed.
20
+ # Example:
21
+ # my_todo rake some-task
22
+ # my_todo rake some-task[args]
23
+ #
24
+ # Runs thor tasks as normal
25
+ # Example:
26
+ # my_todo create --body="hello world"
27
+ # my_todo list
28
+
29
+ if exec_type == 'rake'
30
+ require_relative '../lib/setup'
31
+ require 'rake'
32
+ require 'pp'
33
+
34
+ # Generate standalone migration file configs for sqlite3
35
+ Setup.start(%w[db_config])
36
+ Setup.start(%w[standard_migrations_override])
37
+ # Get current working directory
38
+ pwd=Dir.pwd
39
+ # Go into root of gems directory to load rakefile
40
+ Dir.chdir(gem_dir)
41
+ Rake.application.init
42
+ Rake.application.load_rakefile
43
+ # Revert to original pwd for any path args passed to task.
44
+ Dir.chdir(pwd)
45
+ # Run the rake task
46
+ Rake.application.invoke_task(ARGV[1])
47
+ else
48
+ # Run normal my_todo task
49
+ require_relative '../lib/my_todo'
50
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ar_base.rb ADDED
@@ -0,0 +1,12 @@
1
+ # @author Lovell McIlwain
2
+ #
3
+ # Handles database connection
4
+ module ArBase
5
+ # Connect to an sqlite3 database located in lib/db
6
+ ActiveRecord::Base.establish_connection(
7
+ adapter: 'sqlite3',
8
+ database: File.expand_path("../db/todos_#{ENV['RAILS_ENV']}.sqlite3", __FILE__),
9
+ pool: 5,
10
+ encoding: 'utf8'
11
+ )
12
+ end
data/lib/db/config.yml ADDED
@@ -0,0 +1,18 @@
1
+ # To Run: rake db:migrate
2
+ development:
3
+ adapter: sqlite3
4
+ database: lib/db/todos_development.sqlite3
5
+ pool: 5
6
+ encoding: utf8
7
+ # To Run: RAILS_ENV=test rake db:migrate
8
+ test:
9
+ adapter: sqlite3
10
+ database: lib/db/todos_test.sqlite3
11
+ pool: 5
12
+ encoding: utf8
13
+ # To Run: RAILS_ENV=production rake db:migrate
14
+ production:
15
+ adapter: sqlite3
16
+ database: lib/db/todos_production.sqlite3
17
+ pool: 5
18
+ encoding: utf8
@@ -0,0 +1,9 @@
1
+ class CreateItems < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :items do |t|
4
+ t.string :body
5
+ t.boolean :done
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class CreateTags < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :tags do |t|
4
+ t.string :name, index: true
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class CreateStubs < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :stubs do |t|
4
+ t.belongs_to :item
5
+ t.belongs_to :tag
6
+ end
7
+ end
8
+ end
data/lib/db/schema.rb ADDED
@@ -0,0 +1,34 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 20160913134610) do
14
+
15
+ create_table "items", force: :cascade do |t|
16
+ t.string "body"
17
+ t.boolean "done"
18
+ t.datetime "created_at", null: false
19
+ t.datetime "updated_at", null: false
20
+ end
21
+
22
+ create_table "stubs", force: :cascade do |t|
23
+ t.integer "item_id"
24
+ t.integer "tag_id"
25
+ t.index ["item_id"], name: "index_stubs_on_item_id"
26
+ t.index ["tag_id"], name: "index_stubs_on_tag_id"
27
+ end
28
+
29
+ create_table "tags", force: :cascade do |t|
30
+ t.string "name"
31
+ t.index ["name"], name: "index_tags_on_name"
32
+ end
33
+
34
+ end
Binary file
data/lib/item.rb ADDED
@@ -0,0 +1,13 @@
1
+ # @author Lovell McIlwain#
2
+ # Handles business logic for todo item
3
+ class Item < ActiveRecord::Base
4
+ # ActiveRecord association to stubs
5
+ # @note Item.first.stubs
6
+ has_many :stubs
7
+ # ActiveRecord association to tags
8
+ # @note Item.first.tags
9
+ # @note destroys associated stubs/tags when deleted
10
+ has_many :tags, through: :stubs, dependent: :destroy
11
+ # ActiveModel validation to ensure body is present
12
+ validates :body, presence: true
13
+ end
@@ -0,0 +1,18 @@
1
+ # To Run: rake db:migrate
2
+ development:
3
+ adapter: sqlite3
4
+ database: <%= GEM_DIR %>/lib/db/todos_development.sqlite3
5
+ pool: 5
6
+ encoding: utf8
7
+ # To Run: RAILS_ENV=test rake db:migrate
8
+ test:
9
+ adapter: sqlite3
10
+ database: <%= GEM_DIR %>/lib/db/todos_test.sqlite3
11
+ pool: 5
12
+ encoding: utf8
13
+ # To Run: RAILS_ENV=production rake db:migrate
14
+ production:
15
+ adapter: sqlite3
16
+ database: <%= GEM_DIR %>/lib/db/todos_production.sqlite3
17
+ pool: 5
18
+ encoding: utf8
@@ -0,0 +1,5 @@
1
+
2
+ ID: <%= item.id %>
3
+ ToDo: <%=item.body %>
4
+ Tags: <%=item.tags.map(&:name).join(', ') %>
5
+ Complete: <%=item.done %>
@@ -0,0 +1,6 @@
1
+ db:
2
+ seeds: <%= GEM_DIR %>/lib/db/seeds.rb
3
+ migrate: <%= GEM_DIR %>/lib/db/migrate
4
+ schema: <%= GEM_DIR %>/lib/db/schema.rb
5
+ config:
6
+ database: <%= GEM_DIR %>/lib/db/config.yml
@@ -0,0 +1,3 @@
1
+ module MyTodo
2
+ VERSION = "1.0.3"
3
+ end
data/lib/my_todo.rb ADDED
@@ -0,0 +1,122 @@
1
+ # @author Lovell McIlwain#
2
+ # Handles running the todo application
3
+ require File.expand_path('../../lib/my_todo/version', __FILE__)
4
+ require 'thor'
5
+ require 'erb'
6
+ require 'sqlite3'
7
+ require 'active_record'
8
+ require 'active_model'
9
+ require 'yaml'
10
+ require_relative 'ar_base'
11
+ require_relative 'item'
12
+ require_relative 'stub'
13
+ require_relative 'tag'
14
+
15
+ module MyTodo
16
+ # Todo tasks using thor gem
17
+ class Todo < Thor
18
+ # Add additional thor tasks
19
+ include Thor::Actions
20
+
21
+ # Private methods/tasks
22
+ no_commands do
23
+ def output(item)
24
+ puts ERB.new(File.read(File.expand_path("../../lib/my_todo/templates/output.erb", __FILE__))).result(binding)
25
+ end
26
+ end
27
+
28
+ desc 'list([REQ])', 'list todos. Default: unfinished, [all], [finished], [unfinished]'
29
+ def list(req=nil)
30
+ items = case
31
+ when req == 'all'
32
+ Item.all
33
+ when req == 'finished'
34
+ Item.where(done: true)
35
+ when req == 'unfinished'
36
+ Item.where(done: false)
37
+ else
38
+ Item.where(done: false)
39
+ end
40
+
41
+ say "ToDos FOUND: #{items.count}"
42
+ items.each {|item| output(item)}
43
+ end
44
+
45
+ desc "create --body='some text' [--done=true] [--tags='tag1 tag2']", 'create a todo'
46
+ option :body
47
+ option :done, default: false
48
+ option :tags, default: 'default'
49
+ option :created_at, default: DateTime.now
50
+ def create
51
+ begin
52
+ item = Item.create!(options.except(:tags))
53
+ options[:tags].split(' ').each{|tag| item.tags.create(name: tag) }
54
+ say 'ToDo CREATED!'
55
+ output item
56
+ rescue ActiveRecord::RecordInvalid => e
57
+ say e.message
58
+ end
59
+ end
60
+
61
+ desc "update --id=1 --body='some text' [--done=true]", 'update an existing todo'
62
+ option :id
63
+ option :body
64
+ option :done
65
+ option :updated_at, default: DateTime.now
66
+ def update
67
+ begin
68
+ item = Item.find(options[:id])
69
+ item.update!(options)
70
+ say 'ToDo UPDATED!'
71
+ output item
72
+ rescue ActiveRecord::RecordInvalid => e
73
+ say e.message
74
+ end
75
+ end
76
+
77
+ desc 'delete(ID)', 'destroy a todo'
78
+ def delete(id)
79
+ begin
80
+ item = Item.find_by_id(id)
81
+ output item
82
+ item.destroy!
83
+ say 'ToDo DESTROYED!'
84
+ rescue Exception => e
85
+ say e.message
86
+ end
87
+ end
88
+
89
+ desc 'search(ID || BODY)', 'search for todo'
90
+ def search(req)
91
+ items = Item.where('id = ? or body like ?', req, "%#{req}%")
92
+ say "ToDos FOUND: #{items.count}"
93
+ items.each {|i| output i}
94
+ end
95
+
96
+ desc "add_tag --todo-id=1 --tag=tag1", 'add a tag to an existing todo'
97
+ option :id
98
+ option :tag
99
+ def add_tag
100
+ begin
101
+ item = Item.where(id: options[:id]).first
102
+ item.tags.create!(name: options[:tag])
103
+ rescue Exception => e
104
+ say e.message
105
+ end
106
+ end
107
+
108
+ desc 'rm_tag --todo-id=1 --tag=tag1', 'remove tag from an existing todo'
109
+ option :id
110
+ option :tag
111
+ def rm_tag
112
+ begin
113
+ item = Item.where(id: options[:id]).first
114
+ item.tags.where(name: options[:tag]).first.destroy!
115
+ output item.reload
116
+ rescue Exception => e
117
+ say e.message
118
+ end
119
+ end
120
+ end
121
+ end
122
+ MyTodo::Todo.start(ARGV)
data/lib/setup.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'thor'
2
+
3
+ # Handles initial setup of application
4
+ class Setup < Thor
5
+ include Thor::Actions
6
+ # Look into the following location for templates
7
+ source_root "#{__dir__}/../lib/my_todo/templates"
8
+ # Store the root of the gem directory
9
+ GEM_DIR = "#{__dir__}/.."
10
+
11
+ desc 'db_config', 'Generate db configuration'
12
+ def db_config
13
+ template "config.yml.erb", "#{__dir__}/../lib/db/config.yml", {quiet: true, force: true}
14
+ end
15
+
16
+ desc 'standard_migrations_override', 'Generate SM override file'
17
+ def standard_migrations_override
18
+ template "standalone_migrations.yml.erb", "#{__dir__}/../.standalone_migrations", {quiet: true, force: true}
19
+ end
20
+ end
data/lib/stub.rb ADDED
@@ -0,0 +1,10 @@
1
+ # @author Lovell McIlwain#
2
+ # Handles business logic for todo stubs
3
+ class Stub < ActiveRecord::Base
4
+ # ActiveRecord assocation to item
5
+ # @note Stub.first.item
6
+ belongs_to :item
7
+ # ActiveRecord assocation to :tag
8
+ # @note Stub.first.tag
9
+ belongs_to :tag
10
+ end
data/lib/tag.rb ADDED
@@ -0,0 +1,12 @@
1
+ # @author Lovell McIlwain#
2
+ # Handles business logic for todo tags
3
+ class Tag < ActiveRecord::Base
4
+ # ActiveRecord asosciation to stubs
5
+ # @note Tag.first.stubs
6
+ has_many :stubs
7
+ # ActiveRecord association to items
8
+ # @note Tag.first.items
9
+ has_many :items, through: :stubs
10
+ # ActiveModel validation for presence of name
11
+ validates :name, presence: true
12
+ end
data/my_todo.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'my_todo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "my_todo"
8
+ spec.version = MyTodo::VERSION
9
+ spec.authors = ["Vell"]
10
+ spec.email = ["lovell.mcilwain@gmail.com"]
11
+
12
+ spec.summary = %q{A basic todo application with tags.}
13
+ spec.description = %q{A terminal based todo application for creating todo items. Adding tags makes for an easy way to group and search for related items.}
14
+ spec.homepage = "https://github.com/vmcilwain/my_todo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = Dir["{bin,lib}/**/*", "LICENSE.txt", "README.md", ".standalone_migrations", 'Rakefile', 'Gemfile', 'my_todo.gemspec']
18
+ spec.test_files = Dir["spec/**/*"]
19
+ spec.bindir = "bin"
20
+ spec.executables = ['my_todo']
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "factory_girl_rails", "~> 4.7.0"
27
+ spec.add_development_dependency "database_cleaner", "~> 1.5.3"
28
+ spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
29
+ spec.add_development_dependency 'byebug', '~> 9.0.5'
30
+ spec.add_development_dependency 'yard', '~> 0.9.5'
31
+ spec.add_dependency 'activerecord', '~> 5.0.0.1'
32
+ spec.add_dependency 'activesupport', '~> 5.0.0.1'
33
+ spec.add_dependency 'thor', '~> 0.19.1'
34
+ spec.add_dependency 'standalone_migrations', '~> 5.0.0'
35
+ spec.add_dependency 'sqlite3', '~> 1.3.11'
36
+
37
+ spec.metadata["yard.run"] = "yri"
38
+ spec.post_install_message = "Don't forget to migrate the db. `my_todo rake db:migrate`"
39
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'add_tag' do
5
+ context 'a successful add' do
6
+ before do
7
+ @todo = FactoryGirl.create(:item)
8
+ MyTodo::Todo.start(%W[add_tag --id=#{@todo.id} --tag=tag1])
9
+ end
10
+ subject {@todo.tags}
11
+ it {is_expected.to include(Tag.first)}
12
+ end
13
+
14
+ context 'an unsuccessful add' do
15
+ before {@todo = FactoryGirl.create(:item)}
16
+
17
+ it 'returns a validation error when tag name is missing' do
18
+ expect{MyTodo::Todo.start(%W[add_tag --id=#{@todo.id} --tag=])}.to output("Validation failed: Name can't be blank\n").to_stdout
19
+ end
20
+
21
+ it 'returns nil exception' do
22
+ expect{MyTodo::Todo.start(%W[add_tag --id=#{@todo.id + 1} --tag=tag1])}.to output("undefined method `tags' for nil:NilClass\n").to_stdout
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'create' do
5
+ context 'successful creation' do
6
+ describe 'creation without tags or setting done attribute' do
7
+ it 'creates a todo item' do
8
+ expect{MyTodo::Todo.start(%w(create --body=wierdness_of_text))}.to change{Item.count}.by(1)
9
+ end
10
+
11
+ it "sets tags to 'default' when tags option is not present" do
12
+ MyTodo::Todo.start(%w[create --body=wierdness_of_text])
13
+ todo = Item.last
14
+ expect(todo.tags.map(&:name)).to eq ['default']
15
+ end
16
+
17
+ it 'sets done to false by when done option is not present' do
18
+ MyTodo::Todo.start(%w[create --body=wierdness_of_text])
19
+ todo = Item.last
20
+ expect(todo.done).to eq false
21
+ end
22
+
23
+ it 'displays the created todo item' do
24
+ expect{MyTodo::Todo.start(%w(create --body=wierdness_of_text))}.to output("ToDo CREATED!\n\nID: 1\nToDo: wierdness_of_text\nTags: default\nComplete: false\n").to_stdout
25
+ end
26
+ end
27
+
28
+ describe 'creation with tags and without setting done attribute' do
29
+ it 'creates associated tag' do
30
+ expect{MyTodo::Todo.start(%w[create --body=wierdness_of_text --tags=tag1])}.to change{Tag.count}.by(1)
31
+ end
32
+
33
+ it 'displays the created todo item with tag' do
34
+ expect{MyTodo::Todo.start(%w(create --body=wierdness_of_text --tags=tag1))}.to output("ToDo CREATED!\n\nID: 1\nToDo: wierdness_of_text\nTags: tag1\nComplete: false\n").to_stdout
35
+ end
36
+ end
37
+
38
+ describe 'create with tags and setting done attribute' do
39
+
40
+ it 'creates todo item with flag set to done' do
41
+ MyTodo::Todo.start(%w[create --body=wierdness_of_text --done=true])
42
+ todo = Item.last
43
+ expect(todo.done).to eq true
44
+ end
45
+
46
+ it 'displays the created to item with complete set to true' do
47
+ expect{MyTodo::Todo.start(%w[create --body=wierdness_of_text --done=true])}.to output("ToDo CREATED!\n\nID: 1\nToDo: wierdness_of_text\nTags: default\nComplete: true\n").to_stdout
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'unsuccessful creation' do
53
+ it 'returns error message when body is missing' do
54
+ expect{MyTodo::Todo.start(%w(create))}.to output("Validation failed: Body can't be blank\n").to_stdout
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'delete' do
5
+ before {@todo = FactoryGirl.create(:item)}
6
+
7
+ it 'destroys todo item' do
8
+ expect{MyTodo::Todo.start(%W(delete #{@todo.id}))}.to change{Item.count}.by(-1)
9
+ end
10
+
11
+ it 'returns nil exception if todo item is invalid' do
12
+ expect{MyTodo::Todo.start(%W[delete #{@todo.id + 1}])}.to output("undefined method `id' for nil:NilClass\n").to_stdout
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'rm_tag' do
5
+ before do
6
+ @todo = FactoryGirl.create(:item)
7
+ @todo.tags.create(name: 'tag1')
8
+ end
9
+ context 'a successful delete' do
10
+ before {MyTodo::Todo.start(%W[rm_tag --id=#{@todo.id} --tag=#{@todo.tags.first.name}])}
11
+ subject {@todo.reload.tags}
12
+ it {is_expected.to eq []}
13
+ end
14
+
15
+ context 'an unsuccessful delete' do
16
+ it 'returns nil exception if item is not found' do
17
+ expect {MyTodo::Todo.start(%W[rm_tag --id=#{@todo.id + 1} --tag=#{@todo.tags.first.name}])}.to output("undefined method `tags' for nil:NilClass\n").to_stdout
18
+ end
19
+
20
+ it 'returns nil exception if tag is not round' do
21
+ expect {MyTodo::Todo.start(%W[rm_tag --id=#{@todo.id} --tag=tag2])}.to output("undefined method `destroy!' for nil:NilClass\n").to_stdout
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'search' do
5
+ context 'success search' do
6
+ before do
7
+ @todo1 = FactoryGirl.create(:item, body: 'nfl')
8
+ @todo2 = FactoryGirl.create(:item, body: 'rocks')
9
+ @todo3 = FactoryGirl.create(:item, body: 'always')
10
+ end
11
+
12
+ it 'finds todo item by id' do
13
+ expect{MyTodo::Todo.start( %W(search #{@todo3.id} ))}.to output("ToDos FOUND: 1\n\nID: 3\nToDo: always\nTags: \nComplete: \n").to_stdout
14
+ end
15
+
16
+ it 'finds todo item by body' do
17
+ expect{MyTodo::Todo.start( %w[search nfl])}.to output("ToDos FOUND: 1\n\nID: 1\nToDo: nfl\nTags: \nComplete: \n").to_stdout
18
+ end
19
+ end
20
+
21
+ context 'unsuccessful search' do
22
+ it 'returns no results when searching by invalid id' do
23
+ expect{MyTodo::Todo.start( %w(search 1))}.to output("ToDos FOUND: 0\n").to_stdout
24
+ end
25
+
26
+ it 'returns no results when searching on invalid body' do
27
+ expect{MyTodo::Todo.start( %w(search no_body))}.to output("ToDos FOUND: 0\n").to_stdout
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'update' do
5
+ before {@todo = FactoryGirl.create(:item)}
6
+ context 'successful update' do
7
+ before {MyTodo::Todo.start(%W(update --id=#{@todo.id} --body=hello))}
8
+ subject {@todo.reload.body}
9
+ it {is_expected.to eq 'hello'}
10
+ end
11
+
12
+ context 'unsuccessful update' do
13
+ it 'returns validation error when body is missing' do
14
+ expect{MyTodo::Todo.start(%W(update --id=#{@todo.id} --body=))}.to output("Validation failed: Body can't be blank\n").to_stdout
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Item, type: :model do
4
+ it {should have_many(:stubs)}
5
+ it {should have_many(:tags)}
6
+ it {should validate_presence_of(:body)}
7
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stub, type: :model do
4
+ it {should belong_to(:item)}
5
+ it {should belong_to(:tag)}
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tag, type: :model do
4
+ it {should validate_presence_of(:name)}
5
+ it {should have_many(:stubs)}
6
+ it {should have_many(:items)}
7
+ end
@@ -0,0 +1,33 @@
1
+ ENV["RAILS_ENV"] = 'test'
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'database_cleaner'
4
+ require 'factory_girl_rails'
5
+ require 'shoulda-matchers'
6
+ require 'byebug'
7
+ require 'my_todo'
8
+
9
+ DatabaseCleaner.strategy = :truncation
10
+
11
+ Shoulda::Matchers.configure do |config|
12
+ config.integrate do |with|
13
+ with.test_framework :rspec
14
+ with.library :active_model
15
+ with.library :active_record
16
+ end
17
+ end
18
+
19
+ Dir['spec/support/**/*.rb'].each { |f| require f }
20
+
21
+ FactoryGirl.define do
22
+ factory :item do
23
+ body "Some Body"
24
+ end
25
+ end
26
+
27
+ RSpec.configure do |config|
28
+ config.before(:each) do
29
+ DatabaseCleaner.clean
30
+ end
31
+ config.include(Shoulda::Matchers::ActiveModel, type: :model)
32
+ config.include(Shoulda::Matchers::ActiveRecord, type: :model)
33
+ end
metadata ADDED
@@ -0,0 +1,274 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_todo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Vell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_girl_rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.7.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.7.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.5.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda-matchers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 9.0.5
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 9.0.5
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.5
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.5
125
+ - !ruby/object:Gem::Dependency
126
+ name: activerecord
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 5.0.0.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 5.0.0.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: activesupport
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 5.0.0.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 5.0.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: thor
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.19.1
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.19.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: standalone_migrations
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 5.0.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 5.0.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: sqlite3
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 1.3.11
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 1.3.11
195
+ description: A terminal based todo application for creating todo items. Adding tags
196
+ makes for an easy way to group and search for related items.
197
+ email:
198
+ - lovell.mcilwain@gmail.com
199
+ executables:
200
+ - my_todo
201
+ extensions: []
202
+ extra_rdoc_files: []
203
+ files:
204
+ - ".standalone_migrations"
205
+ - Gemfile
206
+ - LICENSE.txt
207
+ - README.md
208
+ - Rakefile
209
+ - bin/console
210
+ - bin/my_todo
211
+ - bin/setup
212
+ - lib/ar_base.rb
213
+ - lib/db/config.yml
214
+ - lib/db/migrate/20160912172429_create_items.rb
215
+ - lib/db/migrate/20160913134552_create_tags.rb
216
+ - lib/db/migrate/20160913134610_create_stubs.rb
217
+ - lib/db/schema.rb
218
+ - lib/db/todos_test.sqlite3
219
+ - lib/item.rb
220
+ - lib/my_todo.rb
221
+ - lib/my_todo/templates/config.yml.erb
222
+ - lib/my_todo/templates/output.erb
223
+ - lib/my_todo/templates/standalone_migrations.yml.erb
224
+ - lib/my_todo/version.rb
225
+ - lib/setup.rb
226
+ - lib/stub.rb
227
+ - lib/tag.rb
228
+ - my_todo.gemspec
229
+ - spec/actions/add_tag_spec.rb
230
+ - spec/actions/create_spec.rb
231
+ - spec/actions/delete_spec.rb
232
+ - spec/actions/rm_tag_spec.rb
233
+ - spec/actions/search_spec.rb
234
+ - spec/actions/update_spec.rb
235
+ - spec/models/item_spec.rb
236
+ - spec/models/stub_spec.rb
237
+ - spec/models/tag_spec.rb
238
+ - spec/spec_helper.rb
239
+ homepage: https://github.com/vmcilwain/my_todo
240
+ licenses:
241
+ - MIT
242
+ metadata:
243
+ yard.run: yri
244
+ post_install_message: Don't forget to migrate the db. `my_todo rake db:migrate`
245
+ rdoc_options: []
246
+ require_paths:
247
+ - lib
248
+ required_ruby_version: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: '0'
253
+ required_rubygems_version: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ requirements: []
259
+ rubyforge_project:
260
+ rubygems_version: 2.5.1
261
+ signing_key:
262
+ specification_version: 4
263
+ summary: A basic todo application with tags.
264
+ test_files:
265
+ - spec/actions/add_tag_spec.rb
266
+ - spec/actions/create_spec.rb
267
+ - spec/actions/delete_spec.rb
268
+ - spec/actions/rm_tag_spec.rb
269
+ - spec/actions/search_spec.rb
270
+ - spec/actions/update_spec.rb
271
+ - spec/models/item_spec.rb
272
+ - spec/models/stub_spec.rb
273
+ - spec/models/tag_spec.rb
274
+ - spec/spec_helper.rb