spec/stratify-github/activity_spec.rb in stratify-github-0.1 vs spec/stratify-github/activity_spec.rb in stratify-github-0.1.1

- old
+ new

@@ -7,11 +7,11 @@ D.merge(hsh) end describe Stratify::GitHub::Activity do - context 'save-time requirements' do + context 'model hygiene' do it 'checksums properly' do fields = { 'action' => nil, 'actor' => 'bender', 'url' => 'http://example.com/', @@ -22,62 +22,74 @@ end end context 'translation' do it 'raises an error when the API passes an unknown event type' do - fields = {'type' => 'BendEvent'} + fields = {'type' => 'BendGirderEvent'} lambda {Stratify::GitHub::Activity.from_api_hash(fields)}.should raise_error(GitHubApiError) end it 'produces correct fields for a branch CreateEvent' do data = DM({'type' => 'CreateEvent', - 'url' => 'https://github.com/daemianmack/fake_ruby_project/compare/new', + 'url' => 'https://github.com/daemianmack/clj-cronviz/compare/new', 'payload' => { 'ref' => 'new', 'ref_type' => 'branch'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'CreateEvent' event.ref.should == 'new' event.ref_type.should == 'branch' - event.repository.should == 'https://github.com/daemianmack/fake_ruby_project' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a repo CreateEvent' do data = DM({'type' => 'CreateEvent', - 'url' => 'https://github.com/daemianmack/fake_ruby_project', + 'url' => 'https://github.com/daemianmack/clj-cronviz', 'payload' => { 'ref' => nil, 'ref_type' => 'repository'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'CreateEvent' event.ref.should == nil event.ref_type.should == 'repository' - event.repository.should == 'https://github.com/daemianmack/fake_ruby_project' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a CommitCommentEvent' do data = DM({'type' => 'CommitCommentEvent', - 'url' => 'https://github.com/daemianmack/fake_ruby_project/compare/master'}) + 'url' => 'https://github.com/daemianmack/clj-cronviz/compare/master'}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'CommitCommentEvent' - event.repository.should == 'https://github.com/daemianmack/fake_ruby_project' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a DeleteEvent' do data = DM({'type' => 'DeleteEvent', 'payload' => { 'ref' => 'expendable', 'ref_type' => 'branch'}, 'repository' => { - 'url' => 'https://github.com/daemianmack/fake_ruby_project'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'DeleteEvent' event.ref.should == 'expendable' event.ref_type.should == 'branch' - event.repository.should == 'https://github.com/daemianmack/fake_ruby_project' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end + it 'produces correct fields for a DeleteEvent without a repository' do + data = DM({'type' => 'DeleteEvent', + 'payload' => { + 'ref' => 'expendable', + 'ref_type' => 'branch'}}) + event = Stratify::GitHub::Activity.from_api_hash(data) + event.event_type.should == 'DeleteEvent' + event.ref.should == 'expendable' + event.ref_type.should == 'branch' + event.repository.should be_nil + end + it 'produces correct fields for a FollowEvent' do data = DM({'type' => 'FollowEvent', 'payload' => { 'target' => { 'login' => 'defunkt'}}}) @@ -111,99 +123,112 @@ 'payload' => { 'pages' => [{ 'action' => 'created', 'page_name' => 'Contributing'}]}, 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.action.should == 'created' event.event_type.should == 'GollumEvent' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' event.thing.should == 'Contributing' end - it 'produces correct fields for a IssueCommentEvent' do + it 'produces correct fields for a GollumEvent without a repository' do + data = DM({'type' => 'GollumEvent', + 'payload' => { + 'pages' => [{ + 'action' => 'created', + 'page_name' => 'Contributing'}]}}) + event = Stratify::GitHub::Activity.from_api_hash(data) + event.action.should == 'created' + event.event_type.should == 'GollumEvent' + event.repository.should be_nil + event.thing.should == 'Contributing' + end + + it 'produces correct fields for an IssueCommentEvent' do data = DM({'type' => 'IssueCommentEvent', 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'IssueCommentEvent' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end - it 'produces correct fields for a IssuesEvent' do + it 'produces correct fields for an IssuesEvent' do data = DM({'type' => 'IssuesEvent', 'payload' => { 'action' => 'created'}, - 'url' => 'https://github.com/daemianmack/cronviz'}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}) event = Stratify::GitHub::Activity.from_api_hash(data) event.action.should == 'created' event.event_type.should == 'IssuesEvent' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a MemberEvent' do data = DM({'type' => 'MemberEvent', 'payload' => { 'action' => 'added', 'member' => { 'login' => 'bender'}}, - 'url' => 'https://github.com/daemianmack/cronviz'}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}) event = Stratify::GitHub::Activity.from_api_hash(data) event.action.should == 'added' event.event_type.should == 'MemberEvent' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' event.thing.should == 'bender' end it 'produces correct fields for a PublicEvent' do data = DM({'type' => 'PublicEvent', 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.action.should == 'publicized' event.event_type.should == 'PublicEvent' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a PullRequestEvent' do data = DM({'type' => 'PullRequestEvent', 'payload' => { 'pull_request' => { 'title' => 'Allow time to flow in reverse'}}, 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'PullRequestEvent' event.payload.should == 'Allow time to flow in reverse' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a PullRequestReviewCommentEvent' do data = DM({'type' => 'PullRequestReviewCommentEvent', 'payload' => { 'comment' => { 'body' => 'Please remove all semicolons from this JavaScript.'}}, 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.event_type.should == 'PullRequestReviewCommentEvent' event.payload.should == 'Please remove all semicolons from this JavaScript.' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' end it 'produces correct fields for a PushEvent' do data = DM({'type' => 'PushEvent', 'payload' => { 'ref' => 'refs/head/master', 'shas' => [[nil, nil, 'Fix all the things']]}, 'repository' => { - 'url' => 'https://github.com/daemianmack/cronviz'}}) + 'url' => 'https://github.com/daemianmack/clj-cronviz'}}) event = Stratify::GitHub::Activity.from_api_hash(data) event.action.should == 'pushed' event.event_type.should == 'PushEvent' event.ref.should == 'refs/head/master' - event.repository.should == 'https://github.com/daemianmack/cronviz' + event.repository.should == 'https://github.com/daemianmack/clj-cronviz' event.payload.should == 'Fix all the things' end it 'produces correct fields for a WatchEvent' do data = DM({'type' => 'WatchEvent'})