my_todo 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76a111465e17fce1d2f964cb77123c2f2497102d
4
- data.tar.gz: 9e3e5bdba8b59aaf441e0964c89de22edffc5f38
3
+ metadata.gz: 7d43fa975defc5843e115f0d8258086d03bebf62
4
+ data.tar.gz: 8f8d18f7d47fcceade42a7d8bd22fcfce99e81f5
5
5
  SHA512:
6
- metadata.gz: 8c47ce3d3f0d87c5930de8aae7e32996dbe2d0b2f0002001041b255dbbeed46e04046e87cefb16414895b8cf1eb0275c5a9a05962bb86fb034376c8c579c407f
7
- data.tar.gz: ff1f261f50d0bd60f0d8c20d536cb2d0bc48a542c7c24a3b1220e2972440733350a7cafd7d8369536ae3d6ffa9fd4573c5ee0d2e3d4cb97f3b3c716fe961c6f9
6
+ metadata.gz: ed29e73bb98c43586922c64f549607d8fcff148a708cb5a91c3e5e74e6b7d5fa442d8300138b65ad4d598c1e22684983ea6ce851d21d48c2a6d62c5e10b14347
7
+ data.tar.gz: 5258f53446840229714aec2d8d394753e2587353f56e324978977373d8193efd822fea920d2a68b72b1a75e8baf464a8411c83bab81521e294a9867806ee4ca4
@@ -0,0 +1,9 @@
1
+ class CreateNotes < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :notes do |t|
4
+ t.belongs_to :item
5
+ t.text :body
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
data/lib/db/schema.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20160913134610) do
13
+ ActiveRecord::Schema.define(version: 20161003121448) do
14
14
 
15
15
  create_table "items", force: :cascade do |t|
16
16
  t.string "body"
@@ -19,6 +19,14 @@ ActiveRecord::Schema.define(version: 20160913134610) do
19
19
  t.datetime "updated_at", null: false
20
20
  end
21
21
 
22
+ create_table "notes", force: :cascade do |t|
23
+ t.integer "item_id"
24
+ t.text "body"
25
+ t.datetime "created_at", null: false
26
+ t.datetime "updated_at", null: false
27
+ t.index ["item_id"], name: "index_notes_on_item_id"
28
+ end
29
+
22
30
  create_table "stubs", force: :cascade do |t|
23
31
  t.integer "item_id"
24
32
  t.integer "tag_id"
Binary file
Binary file
data/lib/item.rb CHANGED
@@ -8,6 +8,10 @@ class Item < ActiveRecord::Base
8
8
  # @note Item.first.tags
9
9
  # @note destroys associated stubs/tags when deleted
10
10
  has_many :tags, through: :stubs, dependent: :destroy
11
+ # ActiveRecord association to notes
12
+ # @note Item.first.notes
13
+ # @note destroys associated notes when deleted
14
+ has_many :notes, dependent: :destroy
11
15
  # ActiveModel validation to ensure body is present
12
16
  validates :body, presence: true
13
17
  end
@@ -3,3 +3,9 @@ ID: <%= item.id %>
3
3
  ToDo: <%=item.body %>
4
4
  Tags: <%=item.tags.map(&:name).join(', ') %>
5
5
  Complete: <%=item.done %>
6
+ <% if item.notes.any? %>
7
+ Notes:
8
+ <% item.notes.each do |note| %>
9
+ <%= note.id%>: <%= note.body %>
10
+ <% end %>
11
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module MyTodo
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/lib/my_todo.rb CHANGED
@@ -11,6 +11,7 @@ require_relative 'ar_base'
11
11
  require_relative 'item'
12
12
  require_relative 'stub'
13
13
  require_relative 'tag'
14
+ require_relative 'note'
14
15
 
15
16
  module MyTodo
16
17
  # Todo tasks using thor gem
@@ -58,7 +59,7 @@ module MyTodo
58
59
  end
59
60
  end
60
61
 
61
- desc "update --id=1 --body='some text' [--done=true]", 'update an existing todo'
62
+ desc "update --id=TODO_ID --body='some text' [--done=true]", 'update an existing todo'
62
63
  option :id
63
64
  option :body
64
65
  option :done
@@ -74,7 +75,7 @@ module MyTodo
74
75
  end
75
76
  end
76
77
 
77
- desc 'delete(ID)', 'destroy a todo'
78
+ desc 'delete(TODO_ID)', 'destroy a todo'
78
79
  def delete(id)
79
80
  begin
80
81
  item = Item.find_by_id(id)
@@ -93,10 +94,10 @@ module MyTodo
93
94
  items.each {|i| output i}
94
95
  end
95
96
 
96
- desc "add_tag --todo-id=1 --tag=tag1", 'add a tag to an existing todo'
97
+ desc "tag --id=TODO_ID --tag=TAG_NAME", 'add a tag to an existing todo'
97
98
  option :id
98
99
  option :tag
99
- def add_tag
100
+ def tag
100
101
  begin
101
102
  item = Item.where(id: options[:id]).first
102
103
  item.tags.create!(name: options[:tag])
@@ -105,7 +106,7 @@ module MyTodo
105
106
  end
106
107
  end
107
108
 
108
- desc 'rm_tag --todo-id=1 --tag=tag1', 'remove tag from an existing todo'
109
+ desc 'rm_tag --id=TODO_ID --tag=TAG_NAME', 'remove tag from an existing todo'
109
110
  option :id
110
111
  option :tag
111
112
  def rm_tag
@@ -117,6 +118,33 @@ module MyTodo
117
118
  say e.message
118
119
  end
119
120
  end
121
+
122
+ desc "note --id=TODO_ID --body='text'", 'adds note to existing item'
123
+ option :id
124
+ option :body
125
+ def note
126
+ begin
127
+ item = Item.where(id: options[:id]).first
128
+ item.notes.create(body: options[:body])
129
+ output item.reload
130
+ rescue Exception => e
131
+ say e.message
132
+ end
133
+ end
134
+
135
+ desc 'rm_note --id=TODO_ID --noteid=NOTE_ID', 'remove note for exsiting item'
136
+ option :id
137
+ option :noteid
138
+ def rm_note
139
+ begin
140
+ item = Item.where(id: options[:id]).first
141
+ item.notes.where(id: options[:noteid]).first.destroy!
142
+ output item.reload
143
+ rescue Exception => e
144
+ say e.message
145
+ end
146
+ end
120
147
  end
121
148
  end
149
+
122
150
  MyTodo::Todo.start(ARGV)
data/lib/note.rb ADDED
@@ -0,0 +1,6 @@
1
+ # @author Lovell McIlwain#
2
+ # Handles business logic for todo item
3
+ class Note < ActiveRecord::Base
4
+ validates :body, presence: true
5
+ belongs_to :item
6
+ end
@@ -21,7 +21,7 @@ describe MyTodo do
21
21
  end
22
22
 
23
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
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\n").to_stdout
25
25
  end
26
26
  end
27
27
 
@@ -31,7 +31,7 @@ describe MyTodo do
31
31
  end
32
32
 
33
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
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\n").to_stdout
35
35
  end
36
36
  end
37
37
 
@@ -44,7 +44,7 @@ describe MyTodo do
44
44
  end
45
45
 
46
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
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\n").to_stdout
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'note' do
5
+ before {@todo = FactoryGirl.create(:item)}
6
+ context 'successful creation' do
7
+ it 'creates a note' do
8
+ expect{MyTodo::Todo.start(%W[note --id=#{@todo.id} --body=note_text])}.to change{Note.count}.by(1)
9
+ end
10
+
11
+ it 'associates note to item' do
12
+ MyTodo::Todo.start(%W[note --id=#{@todo.id} --body=note_text])
13
+ expect(@todo.notes.size).to eq 1
14
+ end
15
+
16
+ it 'displays item with notes' do
17
+ expect{MyTodo::Todo.start(%W[note --id=#{@todo.id} --body=note_text])}.to output("\nID: 1\nToDo: Some Body\nTags: \nComplete: \n\nNotes:\n\n1: note_text\n\n\n").to_stdout
18
+ end
19
+ end
20
+
21
+ context 'unsuccessful creation' do
22
+ it 'returns exception if note is not found' do
23
+ expect{MyTodo::Todo.start(%W[note --id=#{@todo.id + 1}])}.to output("undefined method `notes' for nil:NilClass\n").to_stdout
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe MyTodo do
4
+ describe 'rm_note' do
5
+ before do
6
+ @todo = FactoryGirl.create :item
7
+ @todo.notes.create(body: 'Body of text')
8
+ end
9
+
10
+ context 'a successful delete' do
11
+ before {MyTodo::Todo.start(%W[rm_note --id=#{@todo.id} --noteid=#{@todo.notes.first.id}])}
12
+ subject {@todo.reload.notes}
13
+ it {is_expected.to eq []}
14
+ end
15
+
16
+ context 'an unsuccessful delete' do
17
+ it 'returns exception if item is not found' do
18
+ expect {MyTodo::Todo.start(%W[rm_note --id=#{@todo.id + 1} --noteid=#{@todo.notes.first.id}])}.to output("undefined method `notes' for nil:NilClass\n").to_stdout
19
+ end
20
+
21
+ it 'returns exception if note is not found' do
22
+ expect {MyTodo::Todo.start(%W[rm_note --id=#{@todo.id} --noteid=#{@todo.notes.first.id + 1}])}.to output("undefined method `destroy!' for nil:NilClass\n").to_stdout
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,11 +10,11 @@ describe MyTodo do
10
10
  end
11
11
 
12
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
13
+ expect{MyTodo::Todo.start( %W(search #{@todo3.id} ))}.to output("ToDos FOUND: 1\n\nID: 3\nToDo: always\nTags: \nComplete: \n\n").to_stdout
14
14
  end
15
15
 
16
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
17
+ expect{MyTodo::Todo.start( %w[search nfl])}.to output("ToDos FOUND: 1\n\nID: 1\nToDo: nfl\nTags: \nComplete: \n\n").to_stdout
18
18
  end
19
19
  end
20
20
 
@@ -5,7 +5,7 @@ describe MyTodo do
5
5
  context 'a successful add' do
6
6
  before do
7
7
  @todo = FactoryGirl.create(:item)
8
- MyTodo::Todo.start(%W[add_tag --id=#{@todo.id} --tag=tag1])
8
+ MyTodo::Todo.start(%W[tag --id=#{@todo.id} --tag=tag1])
9
9
  end
10
10
  subject {@todo.tags}
11
11
  it {is_expected.to include(Tag.first)}
@@ -15,11 +15,11 @@ describe MyTodo do
15
15
  before {@todo = FactoryGirl.create(:item)}
16
16
 
17
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
18
+ expect{MyTodo::Todo.start(%W[tag --id=#{@todo.id} --tag=])}.to output("Validation failed: Name can't be blank\n").to_stdout
19
19
  end
20
20
 
21
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
22
+ expect{MyTodo::Todo.start(%W[tag --id=#{@todo.id + 1} --tag=tag1])}.to output("undefined method `tags' for nil:NilClass\n").to_stdout
23
23
  end
24
24
  end
25
25
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
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)}
4
+ it {should have_many :stubs}
5
+ it {should have_many :tags}
6
+ it {should have_many :notes}
7
+ it {should validate_presence_of :body}
7
8
  end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Note, type: :model do
4
+ it {should belong_to :item}
5
+ it {should validate_presence_of :body}
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_todo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-01 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -214,7 +214,9 @@ files:
214
214
  - lib/db/migrate/20160912172429_create_items.rb
215
215
  - lib/db/migrate/20160913134552_create_tags.rb
216
216
  - lib/db/migrate/20160913134610_create_stubs.rb
217
+ - lib/db/migrate/20161003121448_create_notes.rb
217
218
  - lib/db/schema.rb
219
+ - lib/db/todos_development.sqlite3
218
220
  - lib/db/todos_test.sqlite3
219
221
  - lib/item.rb
220
222
  - lib/my_todo.rb
@@ -222,17 +224,21 @@ files:
222
224
  - lib/my_todo/templates/output.erb
223
225
  - lib/my_todo/templates/standalone_migrations.yml.erb
224
226
  - lib/my_todo/version.rb
227
+ - lib/note.rb
225
228
  - lib/setup.rb
226
229
  - lib/stub.rb
227
230
  - lib/tag.rb
228
231
  - my_todo.gemspec
229
- - spec/actions/add_tag_spec.rb
230
232
  - spec/actions/create_spec.rb
231
233
  - spec/actions/delete_spec.rb
234
+ - spec/actions/note_spec.rb
235
+ - spec/actions/rm_note_spec.rb
232
236
  - spec/actions/rm_tag_spec.rb
233
237
  - spec/actions/search_spec.rb
238
+ - spec/actions/tag_spec.rb
234
239
  - spec/actions/update_spec.rb
235
240
  - spec/models/item_spec.rb
241
+ - spec/models/note_spec.rb
236
242
  - spec/models/stub_spec.rb
237
243
  - spec/models/tag_spec.rb
238
244
  - spec/spec_helper.rb
@@ -263,13 +269,16 @@ signing_key:
263
269
  specification_version: 4
264
270
  summary: A basic todo application with tags.
265
271
  test_files:
266
- - spec/actions/add_tag_spec.rb
267
272
  - spec/actions/create_spec.rb
268
273
  - spec/actions/delete_spec.rb
274
+ - spec/actions/note_spec.rb
275
+ - spec/actions/rm_note_spec.rb
269
276
  - spec/actions/rm_tag_spec.rb
270
277
  - spec/actions/search_spec.rb
278
+ - spec/actions/tag_spec.rb
271
279
  - spec/actions/update_spec.rb
272
280
  - spec/models/item_spec.rb
281
+ - spec/models/note_spec.rb
273
282
  - spec/models/stub_spec.rb
274
283
  - spec/models/tag_spec.rb
275
284
  - spec/spec_helper.rb