neo-dci 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.simplecov ADDED
@@ -0,0 +1,2 @@
1
+ SimpleCov.coverage_dir "tmp/coverage"
2
+ SimpleCov.start
data/README.md CHANGED
@@ -18,7 +18,68 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ### Data
22
+
23
+ ```ruby
24
+ class User < ActiveRecord::Base
25
+ include Neo::DCI::Data
26
+
27
+ attr_accessible
28
+ end
29
+ ```
30
+
31
+ ### Context
32
+
33
+ ```ruby
34
+ class Context < Neo::DCI::Context
35
+ end
36
+
37
+ class RenameUserContext < Context
38
+ def initialize(user_id, new_name)
39
+ @user = User.find(user_id)
40
+ @new_name = new_name
41
+ end
42
+
43
+ def call(result)
44
+ @user.role_as(Renamer)
45
+ if @user.rename_to(@new_name)
46
+ result.success! :new_name => @new_name
47
+ else
48
+ result.failure! "renaming failed"
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ ### Interaction (Role)
55
+
56
+ ```ruby
57
+ module Renamer
58
+ extend Neo::DCI::Role
59
+
60
+ def rename_to(new_name)
61
+ self.name = new_name
62
+ save
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### Rails Controller
68
+
69
+ ```ruby
70
+ class UsersController < ApplicationController
71
+ def rename
72
+ result = RenameUserContext.call(current_user.id, params[:name])
73
+ if result.success?
74
+ new_name = result.data.new_name
75
+ redirect_to users_path, :notice => "Renamed successfully to #{new_name}"
76
+ else
77
+ error = result.error
78
+ render :alert => "Renaming failed: #{error}!"
79
+ end
80
+ end
81
+ end
82
+ ```
22
83
 
23
84
  ## Contributing
24
85
 
@@ -1,5 +1,5 @@
1
1
  module Neo
2
2
  module DCI
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/neo-dci.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/neo/dci/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Peter Suschlik"]
6
- gem.email = ["ps@neopoly.de"]
5
+ gem.authors = ["Peter Suschlik", "Jakob Holderbaum", "Jonas Thiel"]
6
+ gem.email = ["ps@neopoly.de", "jh@neopoly.de", "jt@neopoly.de"]
7
7
  gem.description = %q{Simple DCI}
8
8
  gem.summary = %q{Includes Data, Roles and Context.}
9
9
  gem.homepage = "https://github.com/neopoly/neo-dci"
@@ -17,5 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rake"
19
19
  gem.add_development_dependency "minitest"
20
- gem.add_development_dependency "simple_assertions"
20
+ gem.add_development_dependency "simplecov"
21
21
  end
@@ -37,6 +37,11 @@ class ContextResultTest < NeoDCICase
37
37
  assert_equal data[:foo], result.data.foo
38
38
  end
39
39
 
40
+ test "returns data as hash" do
41
+ result.success!(data)
42
+ assert_equal data, result.data.to_hash
43
+ end
44
+
40
45
  context "frozen data" do
41
46
  test "after success!" do
42
47
  result.success!
@@ -54,13 +59,13 @@ class ContextResultTest < NeoDCICase
54
59
  end
55
60
 
56
61
  test "with success!" do
57
- assert_raises ArgumentError, :message => /once/ do
62
+ assert_raises ArgumentError do
58
63
  result.success!
59
64
  end
60
65
  end
61
66
 
62
67
  test "with failure!" do
63
- assert_raises ArgumentError, :message => /once/ do
68
+ assert_raises ArgumentError do
64
69
  result.failure!(error)
65
70
  end
66
71
  end
data/test/helper.rb CHANGED
@@ -1,11 +1,10 @@
1
+ require 'simplecov' if ENV['COVERAGE']
2
+
1
3
  require 'minitest/autorun'
2
- require 'simple_assertions'
3
4
 
4
5
  require 'neo/dci'
5
6
 
6
7
  class NeoDCICase < MiniTest::Spec
7
- include SimpleAssertions::AssertRaises
8
-
9
8
  class << self
10
9
  alias :context :describe
11
10
  alias :test :it
data/test/role_test.rb CHANGED
@@ -61,9 +61,11 @@ class RoleTest < NeoDCICase
61
61
  end
62
62
 
63
63
  test "boys don't cry!" do
64
- assert_raises Neo::DCI::Role::NotAssignable, :role => CryBaby, :object => male do
64
+ e = assert_raises Neo::DCI::Role::NotAssignable do
65
65
  male.role_as CryBaby
66
66
  end
67
+ assert_equal CryBaby, e.role
68
+ assert_equal male, e.object
67
69
  end
68
70
 
69
71
  test "emo cores can cry! and growl!" do
metadata CHANGED
@@ -1,15 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo-dci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Suschlik
9
+ - Jakob Holderbaum
10
+ - Jonas Thiel
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-08-09 00:00:00.000000000 Z
14
+ date: 2012-08-24 00:00:00.000000000 Z
13
15
  dependencies:
14
16
  - !ruby/object:Gem::Dependency
15
17
  name: rake
@@ -44,7 +46,7 @@ dependencies:
44
46
  - !ruby/object:Gem::Version
45
47
  version: '0'
46
48
  - !ruby/object:Gem::Dependency
47
- name: simple_assertions
49
+ name: simplecov
48
50
  requirement: !ruby/object:Gem::Requirement
49
51
  none: false
50
52
  requirements:
@@ -62,11 +64,14 @@ dependencies:
62
64
  description: Simple DCI
63
65
  email:
64
66
  - ps@neopoly.de
67
+ - jh@neopoly.de
68
+ - jt@neopoly.de
65
69
  executables: []
66
70
  extensions: []
67
71
  extra_rdoc_files: []
68
72
  files:
69
73
  - .gitignore
74
+ - .simplecov
70
75
  - .travis.yml
71
76
  - Gemfile
72
77
  - LICENSE
@@ -113,3 +118,4 @@ test_files:
113
118
  - test/context_test.rb
114
119
  - test/helper.rb
115
120
  - test/role_test.rb
121
+ has_rdoc: